Sha256: eaf976b48d8126133ef4e85cce9f1e41bcb5a590e355bb38379f1ba4cae6a167
Contents?: true
Size: 859 Bytes
Versions: 21
Compression:
Stored size: 859 Bytes
Contents
class Code class Node class While < Node WHILE_KEYWORD = "while" UNTIL_KEYWORD = "until" def initialize(parsed) @operator = parsed.delete(:operator) @statement = Node::Statement.new(parsed.delete(:statement)) @body = Node::Code.new(parsed.delete(:body)) super(parsed) end 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 end end end
Version data entries
21 entries across 21 versions & 3 rubygems