Class: Red::CallNode::Block

Inherits:
Red::CallNode show all
Defined in:
lib/red/nodes/call_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(function_call_sexp, block_arguments_array_sexp, block_body_sexp = nil, options = {}) ⇒ Block

:iter, expression, | :dasgn_curr | :masgn, [:array, {:dasgn_curr, :dasgn_curr, …]}, (expression | :block)


14
15
16
17
18
19
20
21
22
# File 'lib/red/nodes/call_nodes.rb', line 14

def initialize(function_call_sexp, block_arguments_array_sexp, block_body_sexp = nil, options = {})
  (options = block_body_sexp) && (block_body_sexp = [:block, [:nil]]) if block_body_sexp.is_a?(::Hash)
  block_arguments = block_arguments_array_sexp.is_sexp?(:masgn) ? block_arguments_array_sexp.assoc(:array)[1..-1].map {|dasgn_curr| dasgn_curr.last.red! }.join(",") : (block_arguments_array_sexp && block_arguments_array_sexp != 0 ? block_arguments_array_sexp.last : nil).red!
  block_body      = (block_body_sexp.is_sexp?(:block) ? block_body_sexp : [:block, block_body_sexp]).red!(:force_return => true)
  block_string    = "function(%s){%s;}" % [block_arguments, block_body]
  block_string   << ".m$(this)" unless [:instance_eval, :class_eval].include?(function_call_sexp.last)
  function_call   = function_call_sexp.red!(options.merge(:block_string => block_string))
  self << "%s" % [function_call]
end