Class: Code::Node::ChainedCall

Inherits:
Code::Node show all
Defined in:
lib/code/node/chained_call.rb

Instance Method Summary collapse

Constructor Details

#initialize(parsed) ⇒ ChainedCall

Returns a new instance of ChainedCall.



4
5
6
7
8
9
10
11
12
# File 'lib/code/node/chained_call.rb', line 4

def initialize(parsed)
  @first = Node::Statement.new(parsed.delete(:first))
  @others =
    parsed
      .delete(:others)
      .map { |operator| Node::Statement.new(operator) }

  super(parsed)
end

Instance Method Details

#evaluate(**args) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/code/node/chained_call.rb', line 14

def evaluate(**args)
  first = @first.evaluate(**args)

  @others.reduce(first) do |acc, element|
    element.evaluate(**args.merge(object: acc))
  end
end