Class: WhileNode

Inherits:
Struct
  • Object
show all
Defined in:
lib/toylang/ast/nodes.rb,
lib/toylang/interpreter/evaluation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



45
46
47
# File 'lib/toylang/ast/nodes.rb', line 45

def body
  @body
end

#conditionObject

Returns the value of attribute condition

Returns:

  • (Object)

    the current value of condition



45
46
47
# File 'lib/toylang/ast/nodes.rb', line 45

def condition
  @condition
end

Instance Method Details

#eval(context) ⇒ Object



128
129
130
# File 'lib/toylang/interpreter/evaluation.rb', line 128

def eval(context)
  body.eval(context) while condition.eval(context).ruby_value
end