Class: Cadenza::ConstantNode

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

Overview

The ConstantNode holds a value which is not affected by any context given to it, such as numbers or strings.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ ConstantNode

constructs a new Cadenza::ConstantNode with the given value.

Parameters:

  • value (Object)

    the value of this constant node



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

def initialize(value)
   @value = value
end

Instance Attribute Details

#valueObject

Returns the value of this node.

Returns:

  • (Object)

    the value of this node



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

def value
  @value
end

Instance Method Details

#==(rhs) ⇒ Boolean

Returns if this node and the given one are equivalent by value.

Parameters:

Returns:

  • (Boolean)

    if this node and the given one are equivalent by value



27
28
29
# File 'lib/cadenza/nodes/constant_node.rb', line 27

def ==(rhs)
   @value == rhs.value
end

#eval(context) ⇒ Object

Returns the value of this node evaluated in the given context.

Parameters:

Returns:

  • (Object)

    the value of this node evaluated in the given context



21
22
23
# File 'lib/cadenza/nodes/constant_node.rb', line 21

def eval(context)
   @value
end

#implied_globalsArray

Returns any global variable applied to this node (none).

Returns:

  • (Array)

    any global variable applied to this node (none)



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

def implied_globals
   []
end