Class: Etheruby::ArgumentsGenerator
- Inherits:
-
Object
- Object
- Etheruby::ArgumentsGenerator
- Defined in:
- lib/etheruby/arguments_generator.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(params, args) ⇒ ArgumentsGenerator
constructor
A new instance of ArgumentsGenerator.
- #to_s ⇒ Object
Constructor Details
#initialize(params, args) ⇒ ArgumentsGenerator
Returns a new instance of ArgumentsGenerator.
14 15 16 17 |
# File 'lib/etheruby/arguments_generator.rb', line 14 def initialize(params, args) @params = params @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
12 13 14 |
# File 'lib/etheruby/arguments_generator.rb', line 12 def args @args end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
12 13 14 |
# File 'lib/etheruby/arguments_generator.rb', line 12 def params @params end |
Instance Method Details
#to_s ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/etheruby/arguments_generator.rb', line 19 def to_s raise ArgumentsCountError.new("Bad number of arguments") unless args.count == params.count head = [] tail = '' current_tail_position = 0 (0..params.count-1).each do |i| param, arg = params[i], args[i] if Etheruby.is_static_type? param head << {final: Etheruby.treat_variable(param, arg, :encode).to_s} else head << {pointer: current_tail_position} content = Etheruby.treat_variable(param, arg, :encode).to_s current_tail_position += content.length/2 tail += content end end head_size = head.map { |x| if x.has_key?(:pointer) 32 else x[:final].length/2 end }.inject(0){|sum,x| sum + x } final_head = head.map { |x| if x.has_key?(:pointer) Etheruby::Encoders::Uint.new(head_size + x[:pointer]).encode else x[:final] end }.join return final_head + tail end |