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) ⇒ VariableNode

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

Parameters:



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

def initialize(identifier)
   @identifier = identifier
end

Instance Attribute Details

#identifierString

Returns the name given to this variable.

Returns:

  • (String)

    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.

Parameters:

Returns:



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.

Parameters:

Returns:

  • (Object)

    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_globalsArray

Returns a list of names which are implied to be global variables from this node.

Returns:

  • (Array)

    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