Class: Eqn::Number::SignedNumber

Inherits:
EqnNode
  • Object
show all
Defined in:
lib/eqn/number.rb

Overview

Node class for a signed number.

Instance Method Summary collapse

Methods inherited from EqnNode

#clean_tree!, #term?

Instance Method Details

#value(vars = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/eqn/number.rb', line 22

def value(vars = {})
  first_element = elements.shift
  # If first element is unary minus, negate the following value.
  # Otherwise, simply return the positive value.
  if first_element.is_a?(Terminal::UnaryMinus)
    -elements.shift.value(vars)
  else
    first_element.value(vars)
  end
end