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 = {})
  # Store sign if any.
  sign_negative = elements.shift.negative? if elements.first.is_a?(Terminal::Sign)

  # Evaluate float.
  value = elements.shift.value(vars)

  # Apply sign if any.
  sign_negative ? -value : value
end