Class: Red::ControlNode::Ensure
- Inherits:
-
Red::ControlNode
- Object
- String
- Red::ControlNode
- Red::ControlNode::Ensure
- Defined in:
- lib/red/nodes/control_nodes.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(attempted_sexp, ensure_body_sexp, options) ⇒ Ensure
constructor
[:ensure, | :block, | :block].
Methods inherited from String
#%, #*, #+, #<<, #<=>, #==, #=~, #[], #[]=, #capitalize, #capitalize!, #casecmp, #center, #chomp, #chomp!, #chop, #chop!, #concat, #count, #crypt, #delete, #delete!, #downcase, #downcase!, #each, #each_byte, #each_line, #empty?, #eql?, #gsub, #gsub!, #hash, #hex, #include?, #index, #insert, #inspect, #intern, #length, #ljust, #lstrip, #lstrip!, #match, #next, #next!, #oct, #replace, #reverse, #reverse!, #rindex, #rjust, #rstrip, #rstrip!, #scan, #size, #slice, #slice!, #split, #squeeze, #strip, #strip!, #strip_scripts, #sub, #sub!, #succ, #succ!, #sum, #swapcase, #swapcase!, #to_f, #to_i, #to_s, #to_str, #to_sym, #tr, #tr!, #tr_s, #tr_s!, #upcase, #upcase!, #upto
Constructor Details
#initialize(attempted_sexp, ensure_body_sexp, options) ⇒ Ensure
- :ensure, | :block, | :block
13 14 15 16 17 18 19 20 21 |
# File 'lib/red/nodes/control_nodes.rb', line 13 def initialize(attempted_sexp, ensure_body_sexp, ) #string = (options[:as_argument] || options[:force_return] ? "function(){%s;}()" : "%s") % [string] attempted = (attempted_sexp.is_sexp?(:block, :rescue) ? attempted_sexp : [:block, attempted_sexp]).red!(:force_return => [:force_return]) ensure_body = (ensure_body_sexp.is_sexp?(:block) ? ensure_body_sexp : [:block, ensure_body_sexp]).red!(:force_return => [:force_return]) string = attempted_sexp.is_sexp?(:rescue) ? "%sfinally{%s;}" : "try{%s;}finally{%s;}" self << string % [attempted, ensure_body] end |