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

Returns a new instance of WhileNode.



97
98
99
100
# File 'lib/red/control_nodes.rb', line 97

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



110
111
112
113
# File 'lib/red/control_nodes.rb', line 110

def compile_internals(options = {})
  condition, body = [@condition, @body].compile_nodes
  return [condition, body]
end

#compile_node(options = {}) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/red/control_nodes.rb', line 102

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