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"- LOOP_KEYWORD =
"loop"
Instance Method Summary collapse
- #evaluate(**args) ⇒ Object
-
#initialize(parsed) ⇒ While
constructor
A new instance of While.
Methods inherited from Code::Node
Constructor Details
#initialize(parsed) ⇒ While
Returns a new instance of While.
10 11 12 13 14 15 16 17 18 |
# File 'lib/code/node/while.rb', line 10 def initialize(parsed) return if parsed.blank? @operator = parsed.delete(:operator).presence @statement = Statement.new(parsed.delete(:statement)) if parsed.key?( :statement ) @body = Code.new(parsed.delete(:body).presence) end |
Instance Method Details
#evaluate(**args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/code/node/while.rb', line 20 def evaluate(**args) case @operator when WHILE_KEYWORD evaluate_conditional_loop(condition_truthy: true, **args) when UNTIL_KEYWORD evaluate_conditional_loop(condition_truthy: false, **args) when LOOP_KEYWORD evaluate_infinite_loop(**args) else Object::Nothing.new end end |