Class: BinaryOperationNode
Instance Attribute Summary collapse
-
#lhs ⇒ Object
Returns the value of attribute lhs.
-
#op ⇒ Object
Returns the value of attribute op.
-
#rhs ⇒ Object
Returns the value of attribute rhs.
Attributes inherited from Node
Instance Method Summary collapse
- #evaluate ⇒ Object
-
#initialize(lhs, op, rhs) ⇒ BinaryOperationNode
constructor
A new instance of BinaryOperationNode.
- #to_s ⇒ Object
Constructor Details
#initialize(lhs, op, rhs) ⇒ BinaryOperationNode
Returns a new instance of BinaryOperationNode.
123 124 125 126 |
# File 'lib/nodes/basenodes.rb', line 123 def initialize(lhs, op, rhs) super(op) @lhs, @op, @rhs = lhs, op, rhs end |
Instance Attribute Details
#lhs ⇒ Object
Returns the value of attribute lhs.
121 122 123 |
# File 'lib/nodes/basenodes.rb', line 121 def lhs @lhs end |
#op ⇒ Object
Returns the value of attribute op.
121 122 123 |
# File 'lib/nodes/basenodes.rb', line 121 def op @op end |
#rhs ⇒ Object
Returns the value of attribute rhs.
121 122 123 |
# File 'lib/nodes/basenodes.rb', line 121 def rhs @rhs end |
Instance Method Details
#evaluate ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/nodes/basenodes.rb', line 132 def evaluate if @rhs.evaluate.is_a?(ArrayNode) && @op == '+' return @value = @rhs.evaluate + @lhs.evaluate end if @op == '/' @value = @lhs.evaluate.to_f.send(@op, @rhs.evaluate) else @value = @lhs.evaluate.send(@op, @rhs.evaluate) end end |
#to_s ⇒ Object
128 129 130 |
# File 'lib/nodes/basenodes.rb', line 128 def to_s "#{@lhs} #{@op} #{@rhs}" end |