Class: Red::ControlNode::Rescue

Inherits:
Red::ControlNode show all
Defined in:
lib/red/nodes/control_nodes.rb

Overview

:nodoc:

Instance Method Summary collapse

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, rescue_body_sexp, options = {}) ⇒ Rescue

:rescue, (expression | :block), :resbody


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/red/nodes/control_nodes.rb', line 26

def initialize(attempted_sexp, rescue_body_sexp, options = {})
  (options = rescue_body_sexp) && (rescue_body_sexp = attempted_sexp) && (attempted_sexp = [:nil]) if rescue_body_sexp.is_a?(Hash)
  
  string      = "try{%s;}catch(_e){_eRescued=false;%s;if(!_eRescued){throw(_e);};}"
  if options[:as_argument] || options[:as_assignment]
    string = "function(){%s;}.m$(this)()" % string
    options[:force_return] = true
  end
  attempted   = (attempted_sexp.is_sexp?(:block) ? attempted_sexp : [:block, attempted_sexp]).red!(:force_return => options[:force_return])
  rescue_body = rescue_body_sexp.red!(:force_return => options[:force_return])
  
  self << "try{%s;}catch(_e){_eRescued=false;%s;if(!_eRescued){throw(_e);};}" % [attempted, rescue_body]
end