Class: Basic101::BinaryOperation
- Inherits:
-
Object
- Object
- Basic101::BinaryOperation
- Includes:
- Identity
- Defined in:
- lib/basic101/binary_operation.rb
Instance Method Summary collapse
-
#initialize(operator, right) ⇒ BinaryOperation
constructor
A new instance of BinaryOperation.
- #operate(left, runtime) ⇒ Object
Methods included from Identity
Constructor Details
#initialize(operator, right) ⇒ BinaryOperation
Returns a new instance of BinaryOperation.
11 12 13 14 |
# File 'lib/basic101/binary_operation.rb', line 11 def initialize(operator, right) @operator = operator @right = right end |
Instance Method Details
#operate(left, runtime) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/basic101/binary_operation.rb', line 16 def operate(left, runtime) if @operator.is_a?(Symbol) left_value = left.eval(runtime) right_value = @right.eval(runtime) left_value.public_send(@operator, right_value) else @operator.operate(left, @right, runtime) end end |