Class: Red::ControlNode::WhileNode
- Inherits:
-
Object
- Object
- Red::ControlNode::WhileNode
- Defined in:
- lib/red/control_nodes.rb
Overview
:nodoc:
Instance Method Summary collapse
- #compile_internals(options = {}) ⇒ Object
- #compile_node(options = {}) ⇒ Object
-
#initialize(condition, body, run_only_if_condition_met) ⇒ WhileNode
constructor
A new instance of WhileNode.
Constructor Details
#initialize(condition, body, run_only_if_condition_met) ⇒ WhileNode
98 99 100 101 |
# File 'lib/red/control_nodes.rb', line 98 def initialize(condition, body, run_only_if_condition_met) @condition, @body = [condition, body].build_nodes @do_while_loop = !run_only_if_condition_met end |
Instance Method Details
#compile_internals(options = {}) ⇒ Object
111 112 113 114 115 |
# File 'lib/red/control_nodes.rb', line 111 def compile_internals( = {}) condition = @condition.compile_node(:skip_var => true) body = @body.compile_node return [condition, body] end |
#compile_node(options = {}) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/red/control_nodes.rb', line 103 def compile_node( = {}) if @do_while_loop return "do { %s; } while (%s)" % self.compile_internals.reverse else return "while (%s) { %s; }" % self.compile_internals end end |