Class: BinaryexpressionNode
- Inherits:
-
Object
- Object
- BinaryexpressionNode
- Defined in:
- lib/nodes.rb
Direct Known Subclasses
Instance Method Summary collapse
- #evaluate(scope) ⇒ Object
-
#initialize(lhs, op, rhs) ⇒ BinaryexpressionNode
constructor
A new instance of BinaryexpressionNode.
Constructor Details
#initialize(lhs, op, rhs) ⇒ BinaryexpressionNode
Returns a new instance of BinaryexpressionNode.
194 195 196 197 198 |
# File 'lib/nodes.rb', line 194 def initialize(lhs, op, rhs) @lhs = lhs @op = op @rhs = rhs end |
Instance Method Details
#evaluate(scope) ⇒ Object
200 201 202 203 204 205 206 |
# File 'lib/nodes.rb', line 200 def evaluate(scope) rhs_value = @rhs.evaluate(scope) if @op == :fdiv && rhs_value == 0 raise ZeroDivisionError,"Division by 0 not possible." end return @lhs.evaluate(scope).send(@op, rhs_value) end |