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.
162 163 164 165 |
# File 'lib/nodes/basenodes.rb', line 162 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.
160 161 162 |
# File 'lib/nodes/basenodes.rb', line 160 def lhs @lhs end |
#op ⇒ Object
Returns the value of attribute op.
160 161 162 |
# File 'lib/nodes/basenodes.rb', line 160 def op @op end |
#rhs ⇒ Object
Returns the value of attribute rhs.
160 161 162 |
# File 'lib/nodes/basenodes.rb', line 160 def rhs @rhs end |
Instance Method Details
#evaluate ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/nodes/basenodes.rb', line 171 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
167 168 169 |
# File 'lib/nodes/basenodes.rb', line 167 def to_s "#{@lhs} #{@op} #{@rhs}" end |