Class: WhileLoopNode
Overview
Loop Nodes
Instance Attribute Summary collapse
-
#condition ⇒ Object
Returns the value of attribute condition.
Attributes inherited from Node
Instance Method Summary collapse
- #create_tree_entry ⇒ Object
- #evaluate ⇒ Object
-
#initialize(condition, statement) ⇒ WhileLoopNode
constructor
A new instance of WhileLoopNode.
Methods inherited from Node
Constructor Details
#initialize(condition, statement) ⇒ WhileLoopNode
Returns a new instance of WhileLoopNode.
248 249 250 251 |
# File 'lib/nodes/stmtnodes.rb', line 248 def initialize(condition, statement) @condition = condition super(statement) end |
Instance Attribute Details
#condition ⇒ Object
Returns the value of attribute condition.
246 247 248 |
# File 'lib/nodes/stmtnodes.rb', line 246 def condition @condition end |
Instance Method Details
#create_tree_entry ⇒ Object
253 254 255 256 257 |
# File 'lib/nodes/stmtnodes.rb', line 253 def create_tree_entry result = set_up_scope_header result += "While Loop ran with #{@counter} iterations." TREE_ARRAY << result unless TREE_ARRAY[-1] == result end |
#evaluate ⇒ Object
259 260 261 262 263 264 265 266 267 |
# File 'lib/nodes/stmtnodes.rb', line 259 def evaluate @counter = 0 while @condition.evaluate @value.evaluate @counter += 1 end create_tree_entry if PRINT_TREE_FLAG self.class end |