Class: Rubinius::AST::PatternArguments

Inherits:
Node
  • Object
show all
Defined in:
lib/compiler/ast/definitions.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#line

Class Method Summary collapse

Instance Method Summary collapse

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, arguments) ⇒ PatternArguments

Returns a new instance of PatternArguments.



380
381
382
383
384
# File 'lib/compiler/ast/definitions.rb', line 380

def initialize(line, arguments)
  @line = line
  @arguments = arguments
  @argument = nil
end

Instance Attribute Details

#argumentObject

Returns the value of attribute argument.



364
365
366
# File 'lib/compiler/ast/definitions.rb', line 364

def argument
  @argument
end

#argumentsObject

Returns the value of attribute arguments.



364
365
366
# File 'lib/compiler/ast/definitions.rb', line 364

def arguments
  @arguments
end

Class Method Details

.from_masgn(node) ⇒ Object



366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/compiler/ast/definitions.rb', line 366

def self.from_masgn(node)
  array = []
  node.left.body.map do |n|
    case n
    when MultipleAssignment
      array << PatternArguments.from_masgn(n)
    when LocalVariable
      array << PatternVariable.new(n.line, n.name)
    end
  end

  PatternArguments.new node.line, ArrayLiteral.new(node.line, array)
end

Instance Method Details

#map_arguments(scope) ⇒ Object

Assign the left-most, depth-first PatternVariable so that this local will be assigned the passed argument at that position. The rest of the pattern will be destructured from the value of this assignment.



389
390
391
392
393
394
395
396
397
398
399
400
# File 'lib/compiler/ast/definitions.rb', line 389

def map_arguments(scope)
  arguments = @arguments.body
  while arguments
    node = arguments.first
    if node.kind_of? PatternVariable
      @argument = node
      scope.assign_local_reference node
      return
    end
    arguments = node.arguments.body
  end
end