Class: Romanesco::UnaryOperator

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

Direct Known Subclasses

ParenthesesOperator

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) ⇒ UnaryOperator

Returns a new instance of UnaryOperator.



8
9
10
# File 'lib/romanesco/elements/unary_operator.rb', line 8

def initialize(symbol)
  @symbol = symbol
end

Instance Attribute Details

#operandObject

Returns the value of attribute operand.



6
7
8
# File 'lib/romanesco/elements/unary_operator.rb', line 6

def operand
  @operand
end

#symbolObject

Returns the value of attribute symbol.



6
7
8
# File 'lib/romanesco/elements/unary_operator.rb', line 6

def symbol
  @symbol
end

Instance Method Details

#evaluate(options) ⇒ Object



12
13
14
15
# File 'lib/romanesco/elements/unary_operator.rb', line 12

def evaluate(options)
  check_for_blank_symbol
  @result = @operand.evaluate(options)
end

#insert_element(element) ⇒ Object



29
30
31
32
33
# File 'lib/romanesco/elements/unary_operator.rb', line 29

def insert_element(element)
  @operand = element
  element.parent = self if element
  element
end

#insert_element_to_left(element) ⇒ Object



21
22
23
# File 'lib/romanesco/elements/unary_operator.rb', line 21

def insert_element_to_left(element)
  insert_element(element)
end

#insert_element_to_right(element) ⇒ Object



25
26
27
# File 'lib/romanesco/elements/unary_operator.rb', line 25

def insert_element_to_right(element)
  insert_element(element)
end

#to_sObject



17
18
19
# File 'lib/romanesco/elements/unary_operator.rb', line 17

def to_s
  "(#{@operand.to_s})"
end