Class: Red::CallNode::BlockNode

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(receiver, arguments_array, expression = nil) ⇒ BlockNode

Returns a new instance of BlockNode.



4
5
6
7
# File 'lib/red/call_nodes.rb', line 4

def initialize(receiver, arguments_array, expression = nil)
  @receiver, @expression = [receiver, expression].build_nodes
  @arguments = (((arguments_array ||= []).first == :masgn) ? arguments_array.assoc(:array)[1..-1].map {|node| node.last} : [arguments_array.last]).build_nodes
end

Instance Method Details

#compile_node(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/red/call_nodes.rb', line 9

def compile_node(options = {})
  receiver = @receiver.compile_node.gsub(/\(\)$/,'')
  arguments = @arguments.compile_nodes.join(', ')
  expression = @expression.compile_node
  case receiver.to_sym
  when :lambda, :function, :proc
    "function(%s) { %s }" % [arguments, expression]
  else
    "%s(function(%s) { %s })" % [receiver, arguments, expression]
  end
end