Class: Code::Node::Operation
- Inherits:
-
Code::Node
- Object
- Code::Node
- Code::Node::Operation
- Defined in:
- lib/code/node/operation.rb
Defined Under Namespace
Classes: Operator
Instance Method Summary collapse
- #evaluate(**args) ⇒ Object
-
#initialize(parsed) ⇒ Operation
constructor
A new instance of Operation.
Constructor Details
#initialize(parsed) ⇒ Operation
Returns a new instance of Operation.
13 14 15 16 17 18 19 20 21 |
# File 'lib/code/node/operation.rb', line 13 def initialize(parsed) @first = Node::Statement.new(parsed.delete(:first)) @others = parsed .delete(:others) .map { |operator| Node::Operation::Operator.new(operator) } super(parsed) end |
Instance Method Details
#evaluate(**args) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/code/node/operation.rb', line 23 def evaluate(**args) first = @first.evaluate(**args) @others.reduce(first) do |left, right| statement = right.statement.evaluate(**args) left.call( operator: right.operator, arguments: [::Code::Object::Argument.new(statement)], **args ) end end |