Class: Rubinius::AST::FormalArguments19
Instance Attribute Summary collapse
#block_arg, #defaults, #names, #optional, #required, #splat
Attributes inherited from Node
#line
Instance Method Summary
collapse
#to_actual, #to_sexp
Methods inherited from Node
#ascii_graph, #attributes, #children, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, node_name, #pos, #set_child, #to_sexp, #transform, transform, transform_comment, transform_kind, transform_kind=, transform_name, #visit, #walk
Constructor Details
#initialize(line, required, optional, splat, post, block) ⇒ FormalArguments19
Returns a new instance of FormalArguments19.
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
# File 'lib/compiler/ast/definitions.rb', line 263
def initialize(line, required, optional, splat, post, block)
@line = line
@defaults = nil
@block_arg = nil
@splat_index = nil
@required = []
names = []
if required
required.each do |arg|
case arg
when Symbol
names << arg
@required << arg
when MultipleAssignment
@required << PatternArguments.from_masgn(arg)
@splat_index = -4 if @required.size == 1
end
end
end
if optional
@defaults = DefaultArguments.new line, optional
@optional = @defaults.names
names.concat @optional
else
@optional = []
end
case splat
when Symbol
names << splat
when true
splat = :@unnamed_splat
names << splat
when false
@splat_index = -3
splat = nil
end
if post
names.concat post
@post = post
else
@post = []
end
if block
@block_arg = BlockArgument.new line, block
names << block
end
@splat = splat
@names = names
end
|
Instance Attribute Details
#post ⇒ Object
Returns the value of attribute post.
261
262
263
|
# File 'lib/compiler/ast/definitions.rb', line 261
def post
@post
end
|
Instance Method Details
#map_arguments(scope) ⇒ Object
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
|
# File 'lib/compiler/ast/definitions.rb', line 344
def map_arguments(scope)
@required.each_with_index do |arg, index|
case arg
when PatternArguments
arg.map_arguments scope
when Symbol
@required[index] = arg = :"_#{index}" if arg == :_
scope.new_local arg
end
end
@defaults.map_arguments scope if @defaults
scope.new_local @splat if @splat.kind_of? Symbol
@post.each { |arg| scope.new_local arg }
scope.assign_local_reference @block_arg if @block_arg
end
|
#post_args ⇒ Object
324
325
326
|
# File 'lib/compiler/ast/definitions.rb', line 324
def post_args
@post.size
end
|
#required_args ⇒ Object
320
321
322
|
# File 'lib/compiler/ast/definitions.rb', line 320
def required_args
@required.size + @post.size
end
|
#splat_index ⇒ Object
332
333
334
335
336
337
338
339
340
341
342
|
# File 'lib/compiler/ast/definitions.rb', line 332
def splat_index
return @splat_index if @splat_index
if @splat
index = @names.size
index -= 1 if @block_arg
index -= 1 if @splat.kind_of? Symbol
index -= @post.size
index
end
end
|
#total_args ⇒ Object
328
329
330
|
# File 'lib/compiler/ast/definitions.rb', line 328
def total_args
@required.size + @optional.size + @post.size
end
|