Class: Types::Typed::EnumType

Inherits:
Type
  • Object
show all
Defined in:
lib/solidity/typed/metatypes/types.rb

Overview

note: for bool and enum use DataType or AbstractDataType (ADT)

values must always be from existing set (CANNOT create new values/ones)
  all instances are immutable/frozen and shared

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

Constructor Details

#initialize(enum_name, enum_class) ⇒ EnumType

Returns a new instance of EnumType.



315
316
317
318
# File 'lib/solidity/typed/metatypes/types.rb', line 315

def initialize( enum_name, enum_class )
  @enum_name  = enum_name
  @enum_class = enum_class
end

Instance Attribute Details

#enum_classObject (readonly)

reference enum_class here - why? why not?



314
315
316
# File 'lib/solidity/typed/metatypes/types.rb', line 314

def enum_class
  @enum_class
end

#enum_nameObject (readonly)

Returns the value of attribute enum_name.



313
314
315
# File 'lib/solidity/typed/metatypes/types.rb', line 313

def enum_name
  @enum_name
end

Instance Method Details

#==(other) ⇒ Object



329
330
331
332
333
# File 'lib/solidity/typed/metatypes/types.rb', line 329

def ==(other)
  other.is_a?( EnumType ) &&
  @enum_name  == other.enum_name &&  ## check for name too - why? why not? 
  @enum_class == other.enum_class 
end

#abiObject

note abi requires uint8!!! 0-255 (8bit) todo/check - rename to sig or abisig or selector or ???



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

def abi()  'uint8'; end

#formatObject Also known as: to_s



319
320
321
# File 'lib/solidity/typed/metatypes/types.rb', line 319

def format
   "#{enum_name} enum(#{enum_class.keys.join(',')})" 
end

#mut?Boolean

Returns:

  • (Boolean)


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

def mut?() false; end

#new(initial_value) ⇒ Object



342
343
344
345
# File 'lib/solidity/typed/metatypes/types.rb', line 342

def new( initial_value ) 
   ## allow new use here - why? why not?
   @enum_class.members[ initial_value ] 
end

#typedclassObject



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

def typedclass() @enum_class;  end

#typedclass_nameObject



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

def typedclass_name() @enum_class.name;  end

#zeroObject Also known as: new_zero



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

def zero() @enum_class.zero;  end