Class: Types::Typed::ArrayType

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

Overview

note: dynamic array for now (NOT fixed!!!! - add FixedArray - why? why not?)

Instance Attribute Summary collapse

Class Method 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(sub_type, size = 0) ⇒ ArrayType

Returns a new instance of ArrayType.



18
19
20
21
# File 'lib/solidity/typed/metatypes/array.rb', line 18

def initialize( sub_type, size=0 )
  @sub_type = sub_type
  @size     = size
end

Instance Attribute Details

#sizeObject (readonly)

rename size to dim(ension) or such - why? why not?



17
18
19
# File 'lib/solidity/typed/metatypes/array.rb', line 17

def size
  @size
end

#sub_typeObject (readonly)

Returns the value of attribute sub_type.



16
17
18
# File 'lib/solidity/typed/metatypes/array.rb', line 16

def sub_type
  @sub_type
end

Class Method Details

.instance(sub_type, size = 0) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
# File 'lib/solidity/typed/metatypes/array.rb', line 6

def self.instance( sub_type, size=0 ) 
   raise ArgumentError, "[ArrayType.instance] sub_type not a type - got #{sub_type}; sorry" unless sub_type.is_a?( Type )
   @instances ||= {}
   key = ''  ## note: String.new('') will pick-up TypedString!!; thus, use literal for now 
   key += sub_type.format
   key += "×#{size}"   if size != 0
   @instances[ key ] ||= new( sub_type, size ) 
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
35
# File 'lib/solidity/typed/metatypes/array.rb', line 31

def ==(other)
  other.is_a?( ArrayType ) &&
   @sub_type == other.sub_type &&
   @size     == other.size    ### add check for size too - why? why not?  
end

#formatObject Also known as: to_s



22
23
24
25
26
27
28
# File 'lib/solidity/typed/metatypes/array.rb', line 22

def format
  if @size == 0   ## assume dynamic
     "#{@sub_type.format}[]"   
  else
    "#{@sub_type.format}[#{@size}]"
  end
end

#mut?Boolean

Returns:

  • (Boolean)


49
# File 'lib/solidity/typed/metatypes/array.rb', line 49

def mut?() true; end

#new(initial_value) ⇒ Object



51
# File 'lib/solidity/typed/metatypes/array.rb', line 51

def new( initial_value ) typedclass.new( initial_value ); end

#new_zeroObject



50
# File 'lib/solidity/typed/metatypes/array.rb', line 50

def new_zero()   typedclass.new; end

#typedclassObject



47
# File 'lib/solidity/typed/metatypes/array.rb', line 47

def typedclass()  Types.const_get( typedclass_name ); end

#typedclass_nameObject



38
39
40
41
42
43
44
45
46
# File 'lib/solidity/typed/metatypes/array.rb', line 38

def typedclass_name
  ## return/use symbol (not string here) - why? why not?
  ##  or use TypedArrayOf<sub-type.typedclass_name>  - why? why not?
  sub_name = _sanitize_class_name( @sub_type.typedclass_name )
  name = ''   ## note: String.new('') will pick-up TypedString!!; thus, use literal for now
  name += "Array‹#{sub_name}"
  name += "×#{size}"   if @size != 0
  name 
end