Class: Code::Node::Operation

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

Defined Under Namespace

Classes: Operation

Instance Method Summary collapse

Constructor Details

#initialize(operation) ⇒ Operation

Returns a new instance of Operation.



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

def initialize(operation)
  @first = ::Code::Node::Statement.new(operation.fetch(:first))
  @rest = operation.fetch(:rest)
  @rest.map! do |operation|
    ::Code::Node::Operation::Operation.new(operation)
  end
end

Instance Method Details

#evaluate(**args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/code/node/operation.rb', line 21

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

  @rest.each do |operation|
    other = operation.statement.evaluate(**args)
    object = simple_call(object, operation.operator, other, **args)
  end

  object
end