Class: Romanesco::BinaryOperator
- Inherits:
-
Operator
- Object
- Expression
- Operator
- Romanesco::BinaryOperator
- Defined in:
- lib/romanesco/elements/binary_operator.rb
Direct Known Subclasses
AdditionOperator, DivisionOperator, MultiplicationOperator, SubtractionOperator
Instance Attribute Summary collapse
-
#left_operand ⇒ Object
Returns the value of attribute left_operand.
-
#right_operand ⇒ Object
Returns the value of attribute right_operand.
-
#symbol ⇒ Object
Returns the value of attribute symbol.
Attributes inherited from Expression
Instance Method Summary collapse
- #evaluate(options) ⇒ Object
-
#initialize(symbol) ⇒ BinaryOperator
constructor
A new instance of BinaryOperator.
- #insert_element_to_left(element) ⇒ Object
- #insert_element_to_right(element) ⇒ Object
- #to_s ⇒ Object
Methods inherited from Operator
#check_for_blank_symbol, #connect, #connect_in_place, #connect_in_place_with_parent, #connect_to_left, #connect_to_right, #connect_up_tree, #default_precedence, #precedence, #precedence=
Constructor Details
#initialize(symbol) ⇒ BinaryOperator
Returns a new instance of BinaryOperator.
8 9 10 |
# File 'lib/romanesco/elements/binary_operator.rb', line 8 def initialize(symbol) @symbol = symbol end |
Instance Attribute Details
#left_operand ⇒ Object
Returns the value of attribute left_operand.
6 7 8 |
# File 'lib/romanesco/elements/binary_operator.rb', line 6 def left_operand @left_operand end |
#right_operand ⇒ Object
Returns the value of attribute right_operand.
6 7 8 |
# File 'lib/romanesco/elements/binary_operator.rb', line 6 def right_operand @right_operand end |
#symbol ⇒ Object
Returns the value of attribute symbol.
6 7 8 |
# File 'lib/romanesco/elements/binary_operator.rb', line 6 def symbol @symbol end |
Instance Method Details
#evaluate(options) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/romanesco/elements/binary_operator.rb', line 12 def evaluate() check_for_blank_symbol left_result = @left_operand.evaluate() right_result = @right_operand.evaluate() return left_result, right_result end |
#insert_element_to_left(element) ⇒ Object
23 24 25 26 27 |
# File 'lib/romanesco/elements/binary_operator.rb', line 23 def insert_element_to_left(element) @left_operand = element element.parent = self element end |
#insert_element_to_right(element) ⇒ Object
29 30 31 32 33 |
# File 'lib/romanesco/elements/binary_operator.rb', line 29 def insert_element_to_right(element) @right_operand = element element.parent = self element end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/romanesco/elements/binary_operator.rb', line 19 def to_s "#{@left_operand.to_s} #{symbol} #{@right_operand.to_s}" end |