20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/code/node/while.rb', line 20
def evaluate(**args)
case @operator
when WHILE_KEYWORD
last = Object::Nothing.new
last = @body&.evaluate(**args) || Object::Nothing.new while (
@statement&.evaluate(**args) || Object::Nothing.new
).truthy?
last
when UNTIL_KEYWORD
last = Object::Nothing.new
last = @body&.evaluate(**args) || Object::Nothing.new while (
@statement&.evaluate(**args) || Object::Nothing.new
).falsy?
last
when LOOP_KEYWORD
loop { @body&.evaluate(**args) || Object::Nothing.new }
Object::Nothing.new
else
Object::Nothing.new
end
rescue Error::Break => e
e.value || Object::Nothing.new
end
|