Class: Cadenza::VariableNode
- Inherits:
-
Object
- Object
- Cadenza::VariableNode
- 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
-
#identifier ⇒ String
The name given to this variable.
Instance Method Summary collapse
-
#==(rhs) ⇒ Boolean
If the given VariableNode is equivalent by value to this node.
-
#eval(context) ⇒ Object
Looks up and returns the value of this variable in the given Context.
-
#implied_globals ⇒ Array
A list of names which are implied to be global variables from this node.
-
#initialize(identifier) ⇒ VariableNode
constructor
creates a new VariableNode with the name given.
Constructor Details
#initialize(identifier) ⇒ VariableNode
creates a new Cadenza::VariableNode with the name given.
10 11 12 |
# File 'lib/cadenza/nodes/variable_node.rb', line 10 def initialize(identifier) @identifier = identifier end |
Instance Attribute Details
#identifier ⇒ String
Returns the name given to this variable.
6 7 8 |
# File 'lib/cadenza/nodes/variable_node.rb', line 6 def identifier @identifier end |
Instance Method Details
#==(rhs) ⇒ Boolean
Returns if the given Cadenza::VariableNode is equivalent by value to this node.
30 31 32 |
# File 'lib/cadenza/nodes/variable_node.rb', line 30 def ==(rhs) self.identifier == rhs.identifier end |
#eval(context) ⇒ Object
Returns looks up and returns the value of this variable in the given Context.
23 24 25 |
# File 'lib/cadenza/nodes/variable_node.rb', line 23 def eval(context) context.lookup(@identifier) end |
#implied_globals ⇒ Array
Returns a list of names which are implied to be global variables from this node.
16 17 18 |
# File 'lib/cadenza/nodes/variable_node.rb', line 16 def implied_globals [self.identifier] end |