Class: ExaltedMath::Node::List
- Inherits:
-
ExaltedMath::Node
- Object
- ExaltedMath::Node
- ExaltedMath::Node::List
- Defined in:
- lib/exalted_math/node/list.rb
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
- #==(o) ⇒ Object
- #constant? ⇒ Boolean
-
#initialize(nodes = []) ⇒ List
constructor
A new instance of List.
- #simplify ⇒ Object
- #value(context = {}) ⇒ Object
- #values(context = {}) ⇒ Object
Methods inherited from ExaltedMath::Node
Constructor Details
#initialize(nodes = []) ⇒ List
Returns a new instance of List.
8 9 10 |
# File 'lib/exalted_math/node/list.rb', line 8 def initialize(nodes=[],*) @nodes = nodes end |
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
6 7 8 |
# File 'lib/exalted_math/node/list.rb', line 6 def nodes @nodes end |
Instance Method Details
#==(o) ⇒ Object
32 33 34 35 |
# File 'lib/exalted_math/node/list.rb', line 32 def ==(o) return false unless self.class === o nodes == o.nodes end |
#constant? ⇒ Boolean
12 13 14 |
# File 'lib/exalted_math/node/list.rb', line 12 def constant? nodes.all? { |n| n.constant? } end |
#simplify ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/exalted_math/node/list.rb', line 24 def simplify if constant? Number.new(value) else self end end |
#value(context = {}) ⇒ Object
20 21 22 |
# File 'lib/exalted_math/node/list.rb', line 20 def value(context={}) values(context).inject(0) { |total, value| total += value } end |
#values(context = {}) ⇒ Object
16 17 18 |
# File 'lib/exalted_math/node/list.rb', line 16 def values(context={}) nodes.map { |node| node.value(context) } end |