Class: Cadenza::ConstantNode

Inherits:
Object
  • Object
show all
Includes:
TreeNode
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

Methods included from TreeNode

#to_tree

Constructor Details

#initialize(value) ⇒ ConstantNode

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

Parameters:

  • value (Object)

    the value of this constant node


12
13
14
# File 'lib/cadenza/nodes/constant_node.rb', line 12

def initialize(value)
   @value = value
end

Instance Attribute Details

#valueObject

Returns the value of this node.

Returns:

  • (Object)

    the value of this node


8
9
10
# File 'lib/cadenza/nodes/constant_node.rb', line 8

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


29
30
31
# File 'lib/cadenza/nodes/constant_node.rb', line 29

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


23
24
25
# File 'lib/cadenza/nodes/constant_node.rb', line 23

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)


17
18
19
# File 'lib/cadenza/nodes/constant_node.rb', line 17

def implied_globals
   []
end