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.
24 25 26 27 28 29 30 |
# File 'lib/code/node/left_operation.rb', line 24 def initialize(parsed) return if parsed.blank? @first = Statement.new(parsed.delete(:first).presence) @others = parsed.delete(:others).presence || [] @others.map! { |operator| Operator.new(operator) } end |
Instance Method Details
#evaluate(**args) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/code/node/left_operation.rb', line 32 def evaluate(**args) first = @first&.evaluate(**args) || Object::Nothing.new @others.reduce(first) do |left, right| if right.call? right.statement.evaluate(**args, object: left) else left.call( **args, operator: right.operator, arguments: Object::List.new([right.statement.evaluate(**args)]) ) 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) || Object::Nothing.new list = Object::IdentifierList.new([first]) (@others || []).each do |other| list.code_append( other.statement.resolve(**args, object: list.code_last) ) end list end |