Class: Sol::IfNode

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

Overview

“if” control structure. Look at this node if you want to implement other control structures like while, for, loop, etc.

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



77
78
79
# File 'lib/sol/nodes.rb', line 77

def body
  @body
end

#conditionObject

Returns the value of attribute condition

Returns:

  • (Object)

    the current value of condition



77
78
79
# File 'lib/sol/nodes.rb', line 77

def condition
  @condition
end

Instance Method Details

#eval(context) ⇒ Object



174
175
176
177
178
179
180
181
182
183
# File 'lib/sol/interpreter.rb', line 174

def eval(context)

	# We turn the condition node innto a Ruby value to use Ruby's "if" control structure
	if condition.eval(context).ruby_value

		body.eval(context)

	end

end