Class: VariableDecNode

Inherits:
Node
  • Object
show all
Defined in:
lib/nodes/stmtnodes.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#value

Instance Method Summary collapse

Constructor Details

#initialize(name, value) ⇒ VariableDecNode

Returns a new instance of VariableDecNode.



38
39
40
41
# File 'lib/nodes/stmtnodes.rb', line 38

def initialize(name, value)
  super(value)
  @name = name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



36
37
38
# File 'lib/nodes/stmtnodes.rb', line 36

def name
  @name
end

Instance Method Details

#create_tree_entryObject



43
44
45
46
47
# File 'lib/nodes/stmtnodes.rb', line 43

def create_tree_entry
  result = set_up_scope_header
  result += "Variable #{@name} is now  #{@value}"
  TREE_ARRAY << result unless TREE_ARRAY[-1] == result
end

#evaluateObject



53
54
55
56
57
# File 'lib/nodes/stmtnodes.rb', line 53

def evaluate
  ScopeManager.add_to_current_scope(name, @value)
  create_tree_entry if PRINT_TREE_FLAG
  self
end

#to_sObject



49
50
51
# File 'lib/nodes/stmtnodes.rb', line 49

def to_s
  "#{@name} = #{@value}"
end