Class: ExaltedMath::Node::Named

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

Direct Known Subclasses

Spec, Stat

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ExaltedMath::Node

#simplify

Constructor Details

#initialize(name) ⇒ Named

Returns a new instance of Named.



7
8
9
# File 'lib/exalted_math/node/named.rb', line 7

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/exalted_math/node/named.rb', line 6

def name
  @name
end

Instance Method Details

#==(o) ⇒ Object



25
26
27
28
# File 'lib/exalted_math/node/named.rb', line 25

def ==(o)
  return false unless self.class === o
  self.name == o.name
end

#constant?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/exalted_math/node/named.rb', line 11

def constant?
  false
end

#valid?(stats) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/exalted_math/node/named.rb', line 30

def valid?(stats)
  stats.include?(name)
end

#value(context = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/exalted_math/node/named.rb', line 15

def value(context={})
  if context.respond_to?(:fetch)
    context.fetch(name) { raise ContextError, name }
  elsif context.respond_to?(name)
    context.public_send(name)
  else
    raise ContextError, name
  end
end