Class: Romanesco::BinaryOperator

Inherits:
Operator show all
Defined in:
lib/romanesco/elements/binary_operator.rb

Instance Attribute Summary collapse

Attributes inherited from Expression

#parent

Instance Method Summary collapse

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_operandObject

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_operandObject

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

#symbolObject

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(options)
  check_for_blank_symbol
  left_result = @left_operand.evaluate(options)
  right_result = @right_operand.evaluate(options)
  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_sObject



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