Class: ExaltedMath::Node::List

Inherits:
ExaltedMath::Node show all
Defined in:
lib/exalted_math/node/list.rb

Direct Known Subclasses

Maximum, Minimum

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ExaltedMath::Node

#valid?

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

#nodesObject (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

Returns:

  • (Boolean)


12
13
14
# File 'lib/exalted_math/node/list.rb', line 12

def constant?
  nodes.all? { |n| n.constant? }
end

#simplifyObject



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