Class: Confuscript::Nodes::Expressions::ArithmeticNode

Inherits:
BaseNode
  • Object
show all
Defined in:
lib/confuscript/nodes/expressions/arithmetic_node.rb

Instance Method Summary collapse

Methods inherited from BaseNode

#find_node

Instance Method Details

#evaluate(context) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/confuscript/nodes/expressions/arithmetic_node.rb', line 5

def evaluate(context)
  left_value = elements[0].evaluate(context)
  
  # For more than two operands, we need to check if the next elemnt
  # is a value or another arithmetic operation.
  if elements[4].is_a?(Confuscript::Nodes::Expressions::ArithmeticNode)
    right_value = elements[4].evaluate(context)
  else
    right_value = elements[4].evaluate(context)
  end

  operator.evaluate(left_value, right_value)
end