Class: BinaryexpressionNode
- Inherits:
-
Object
- Object
- BinaryexpressionNode
- Defined in:
- lib/nodes.rb
Overview
Super class for arithmetic and logical expressions.
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.
247 248 249 250 251 |
# File 'lib/nodes.rb', line 247 def initialize(lhs, op, rhs) @lhs = lhs @op = op @rhs = rhs end |
Instance Method Details
#evaluate(scope) ⇒ Object
253 254 255 256 257 258 259 260 261 |
# File 'lib/nodes.rb', line 253 def evaluate(scope) rhs_value = @rhs.evaluate(scope) # Dividing by 0 using using fdiv returns Infinity, raise ZeroDivisionError instead. if @op == :fdiv && rhs_value == 0 raise ZeroDivisionError,"Division by 0 not possible." end return @lhs.evaluate(scope).send(@op, rhs_value) end |