Class: IfElseNode
- Inherits:
-
Struct
- Object
- Struct
- IfElseNode
- Defined in:
- lib/toylang/ast/nodes.rb,
lib/toylang/interpreter/evaluation.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#else_body ⇒ Object
Returns the value of attribute else_body.
Instance Method Summary collapse
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
44 45 46 |
# File 'lib/toylang/ast/nodes.rb', line 44 def body @body end |
#condition ⇒ Object
Returns the value of attribute condition
44 45 46 |
# File 'lib/toylang/ast/nodes.rb', line 44 def condition @condition end |
#else_body ⇒ Object
Returns the value of attribute 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 |