Class: Web3::Eth::Abi::Tuple
Instance Attribute Summary collapse
-
#parsed_types ⇒ Object
readonly
Returns the value of attribute parsed_types.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Attributes inherited from Type
Class Method Summary collapse
Instance Method Summary collapse
- #==(another_type) ⇒ Object
- #calculate_size ⇒ Object
-
#initialize(types, dims) ⇒ Tuple
constructor
A new instance of Tuple.
- #size ⇒ Object
- #subtype ⇒ Object
Methods inherited from Type
Constructor Details
Instance Attribute Details
#parsed_types ⇒ Object (readonly)
Returns the value of attribute parsed_types.
159 160 161 |
# File 'lib/web3/eth/abi/type.rb', line 159 def parsed_types @parsed_types end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
159 160 161 |
# File 'lib/web3/eth/abi/type.rb', line 159 def types @types end |
Class Method Details
.parse(types, dims) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/web3/eth/abi/type.rb', line 127 def self.parse types, dims depth = 0 collected = [] current = '' types.split('').each do |c| case c when ',' then if depth==0 collected << current current = '' else current += c end when '(' then depth += 1 current += c when ')' then depth -= 1 current += c else current += c end end collected << current unless current.empty? Tuple.new collected, dims.map {|x| x[1...-1].to_i} end |
Instance Method Details
#==(another_type) ⇒ Object
166 167 168 169 170 |
# File 'lib/web3/eth/abi/type.rb', line 166 def ==(another_type) another_type.kind_of?(Tuple) && another_type.types == types && another_type.dims == dims end |
#calculate_size ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/web3/eth/abi/type.rb', line 176 def calculate_size if dims.empty? s = 0 parsed_types.each do |type| ts = type.size return nil if ts.nil? s += ts end s else if dims.last == 0 # 0 for dynamic array [] nil else subtype.dynamic? ? nil : dims.last * subtype.size end end end |
#size ⇒ Object
172 173 174 |
# File 'lib/web3/eth/abi/type.rb', line 172 def size @size ||= calculate_size end |