Class: IfElseNode

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



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

def body
  @body
end

#conditionObject

Returns the value of attribute condition

Returns:

  • (Object)

    the current value of condition



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

def condition
  @condition
end

#else_bodyObject

Returns the value of attribute else_body

Returns:

  • (Object)

    the current value of else_body



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

def else_body
  @else_body
end

Instance Method Details

#eval(context) ⇒ Object



116
117
118
119
120
121
122
123
124
# File 'lib/toylang/interpreter/evaluation.rb', line 116

def eval(context)
  if condition.eval(context).ruby_value
    body.eval(context)
  elsif else_body.nil?
    Runtime['nil']
  else
    else_body.eval(context)
  end
end