Class: Types::Typed::StructType

Inherits:
ReferenceType show all
Defined in:
lib/solidity/typed/metatypes/types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

#array?, #check_and_normalize_literal, #eql?, #hash, #mapping?, #parse_integer, #pretty_print, #raise_type_error, #zero

Constructor Details

#initialize(struct_name, struct_class) ⇒ StructType

Returns a new instance of StructType.



353
354
355
356
# File 'lib/solidity/typed/metatypes/types.rb', line 353

def initialize( struct_name, struct_class )
  @struct_name  = struct_name
  @struct_class = struct_class
end

Instance Attribute Details

#struct_classObject (readonly)

reference struct_class here - why? why not?



352
353
354
# File 'lib/solidity/typed/metatypes/types.rb', line 352

def struct_class
  @struct_class
end

#struct_nameObject (readonly)

Returns the value of attribute struct_name.



351
352
353
# File 'lib/solidity/typed/metatypes/types.rb', line 351

def struct_name
  @struct_name
end

Instance Method Details

#==(other) ⇒ Object



371
372
373
374
375
# File 'lib/solidity/typed/metatypes/types.rb', line 371

def ==(other)
  other.is_a?( StructType ) &&
  @struct_name  == other.struct_name &&  ## check for name too - why? why not? 
  @struct_class == other.struct_class 
end

#abiObject

note: abi requires “tuple()”



366
367
368
369
# File 'lib/solidity/typed/metatypes/types.rb', line 366

def abi
 types = @struct_class.attributes.map  {|_,type| type.abi }
 "tuples(#{types.join(',')})" 
end

#formatObject Also known as: to_s



357
358
359
360
361
# File 'lib/solidity/typed/metatypes/types.rb', line 357

def format
  ## use tuple here (not struct) - why? why not?
   named_types = @struct_class.attributes.map  {|key,type| "#{key} #{type.format}" }
   "#{@struct_name} struct(#{named_types.join(',')})" 
end

#mut?Boolean

note: mut? == true MUST use new_zero (dup)

mut? == false MUST use zero (frozen/shared/singelton)

Returns:

  • (Boolean)


383
# File 'lib/solidity/typed/metatypes/types.rb', line 383

def mut?() true; end

#new(initial_values) ⇒ Object

todo/check: change to values with splat - why? why not?



385
386
387
388
389
# File 'lib/solidity/typed/metatypes/types.rb', line 385

def new( initial_values )  ## todo/check: change to values with splat - why? why not?  
    ## note: use "splat" here - must be empty or matching number of fields/attributes
    ##  change - why? why not?
   @struct_class.new( *initial_values ) 
end

#new_zeroObject



384
# File 'lib/solidity/typed/metatypes/types.rb', line 384

def new_zero() @struct_class.new_zero; end

#typedclassObject



379
# File 'lib/solidity/typed/metatypes/types.rb', line 379

def typedclass() @struct_class;  end

#typedclass_nameObject



378
# File 'lib/solidity/typed/metatypes/types.rb', line 378

def typedclass_name() @struct_class.name;  end