Class: Cadenza::VariableNode

Inherits:
Object
  • Object
show all
Defined in:
lib/cadenza/nodes/variable_node.rb

Overview

The VariableNode holds a variable name (identifier) which it can render the value of given a Context with the name defined in it's variable stack.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, parameters = []) ⇒ VariableNode

creates a new Cadenza::VariableNode with the name given.



15
16
17
18
# File 'lib/cadenza/nodes/variable_node.rb', line 15

def initialize(identifier, parameters=[])
   @identifier = identifier
   @parameters = parameters
end

Instance Attribute Details

#identifierString



6
7
8
# File 'lib/cadenza/nodes/variable_node.rb', line 6

def identifier
  @identifier
end

#parametersArray



10
11
12
# File 'lib/cadenza/nodes/variable_node.rb', line 10

def parameters
  @parameters
end

Instance Method Details

#==(rhs) ⇒ Boolean



43
44
45
# File 'lib/cadenza/nodes/variable_node.rb', line 43

def ==(rhs)
   self.identifier == rhs.identifier && self.parameters == rhs.parameters
end

#eval(context) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/cadenza/nodes/variable_node.rb', line 29

def eval(context)
   value = context.lookup(@identifier)

   if value.is_a? Proc
     args = parameters.map {|p| p.eval(context) }
     value = value.call(context, *args)
   end

   value
end

#implied_globalsArray



22
23
24
# File 'lib/cadenza/nodes/variable_node.rb', line 22

def implied_globals
   ([self.identifier] + @parameters.map(&:implied_globals).flatten).uniq
end