Class: Red::ControlNode::EnsureNode

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(attempted, ensure_body) ⇒ EnsureNode

Returns a new instance of EnsureNode.



15
16
17
18
# File 'lib/red/control_nodes.rb', line 15

def initialize(attempted, ensure_body)
  @@rescue_is_safe = @ensure_from_rescue = attempted.first == :rescue
  @attempted, @ensured = [attempted, ensure_body].build_nodes
end

Instance Method Details

#compile_internals(options = {}) ⇒ Object



28
29
30
# File 'lib/red/control_nodes.rb', line 28

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

#compile_node(options = {}) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/red/control_nodes.rb', line 20

def compile_node(options = {})
  if @ensure_from_rescue
    "%s finally { %s; }" 
  else
    "try { %s; } finally { %s; }"
  end % self.compile_internals
end