Class: Red::ControlNode::WhileNode

Inherits:
Object
  • Object
show all
Defined in:
lib/red/control_nodes.rb

Overview

:nodoc:

Instance Method Summary collapse

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(options = {})
  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(options = {})
  if @do_while_loop
    return "do { %s; } while (%s)" % self.compile_internals.reverse
  else
    return "while (%s) { %s; }" % self.compile_internals
  end
end