Class: Code::Node::LeftOperation
- Inherits:
-
Code::Node
- Object
- Code::Node
- Code::Node::LeftOperation
- Defined in:
- lib/code/node/left_operation.rb
Defined Under Namespace
Classes: Operator
Instance Method Summary collapse
- #evaluate(**args) ⇒ Object
-
#initialize(parsed) ⇒ LeftOperation
constructor
A new instance of LeftOperation.
- #resolve(**args) ⇒ Object
Constructor Details
#initialize(parsed) ⇒ LeftOperation
Returns a new instance of LeftOperation.
22 23 24 25 26 27 28 |
# File 'lib/code/node/left_operation.rb', line 22 def initialize(parsed) @first = Statement.new(parsed.delete(:first)) @others = parsed.delete(:others).map { |operator| Operator.new(operator) } super(parsed) end |
Instance Method Details
#evaluate(**args) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/code/node/left_operation.rb', line 30 def evaluate(**args) first = @first.evaluate(**args) @others.reduce(first) do |left, right| if right.call? right.statement.evaluate(**args, object: left) else statement = right.statement.evaluate(**args) left.call( **args, operator: right.operator, arguments: [::Code::Object::Argument.new(statement)] ) end end end |
#resolve(**args) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/code/node/left_operation.rb', line 48 def resolve(**args) first = @first.resolve(**args) list = Object::IdentifierList.new([first]) @others.each do |other| list.code_append( other.statement.resolve(**args, object: list.code_last) ) end list end |