Class: Code::Node::While
- Inherits:
-
Code::Node
- Object
- Code::Node
- Code::Node::While
- Defined in:
- lib/code/node/while.rb
Constant Summary collapse
- WHILE_KEYWORD =
"while"
- UNTIL_KEYWORD =
"until"
Instance Method Summary collapse
- #evaluate(**args) ⇒ Object
-
#initialize(parsed) ⇒ While
constructor
A new instance of While.
Constructor Details
Instance Method Details
#evaluate(**args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/code/node/while.rb', line 14 def evaluate(**args) if @operator == WHILE_KEYWORD last = ::Code::Object::Nothing.new while @statement.evaluate(**args).truthy? last = @body.evaluate(**args) end last elsif @operator == UNTIL_KEYWORD last = ::Code::Object::Nothing.new last = @body.evaluate(**args) while @statement.evaluate(**args).falsy? last else raise NotImplementedError.new(@operator) end end |