Class: Rubinius::ToolSet.current::TS::AST::PatternArguments
- Defined in:
- lib/rubinius/ast/definitions.rb
Instance Attribute Summary collapse
-
#argument ⇒ Object
Returns the value of attribute argument.
-
#arguments ⇒ Object
Returns the value of attribute arguments.
Attributes inherited from Node
Class Method Summary collapse
Instance Method Summary collapse
- #bytecode(g) ⇒ Object
-
#initialize(line, arguments) ⇒ PatternArguments
constructor
A new instance of PatternArguments.
-
#map_arguments(scope) ⇒ Object
Assign the left-most, depth-first PatternVariable so that this local will be assigned the passed argument at that position.
Methods inherited from Node
#ascii_graph, #attributes, #children, #defined, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, #or_bytecode, #pos, #set_child, #to_sexp, #transform, transform, transform_comment, transform_kind, transform_kind=, transform_name, #value_defined, #visit, #walk
Constructor Details
#initialize(line, arguments) ⇒ PatternArguments
Returns a new instance of PatternArguments.
586 587 588 589 590 |
# File 'lib/rubinius/ast/definitions.rb', line 586 def initialize(line, arguments) @line = line @arguments = arguments @argument = nil end |
Instance Attribute Details
#argument ⇒ Object
Returns the value of attribute argument.
541 542 543 |
# File 'lib/rubinius/ast/definitions.rb', line 541 def argument @argument end |
#arguments ⇒ Object
Returns the value of attribute arguments.
541 542 543 |
# File 'lib/rubinius/ast/definitions.rb', line 541 def arguments @arguments end |
Class Method Details
.from_masgn(node) ⇒ Object
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 |
# File 'lib/rubinius/ast/definitions.rb', line 543 def self.from_masgn(node) array = [] size = 0 if node.left size += node.left.body.size node.left.body.map do |n| case n when MultipleAssignment array << PatternArguments.from_masgn(n) when LocalVariable array << LeftPatternVariable.new(n.line, n.name) end end end if node.post idx = 0 post_args = [] node.post.body.map do |n| case n when MultipleAssignment post_args << PatternArguments.from_masgn(n) when LocalVariable post_args << PostPatternVariable.new(n.line, n.name, idx) end idx += 1 end array.concat(post_args.reverse) end if node.splat n = node.splat case n when EmptySplat array << SplatPatternVariable.new(n.line, :*) when SplatAssignment, SplatWrapped, SplatArray array << SplatPatternVariable.new(n.value.line, n.value.name) end end PatternArguments.new node.line, ArrayLiteral.new(node.line, array) end |
Instance Method Details
#bytecode(g) ⇒ Object
610 611 612 613 614 615 616 617 618 619 620 621 |
# File 'lib/rubinius/ast/definitions.rb', line 610 def bytecode(g) @arguments.body.each do |arg| if arg.kind_of? PatternArguments g.shift_array g.cast_array arg.bytecode(g) g.pop else arg.bytecode(g) end end end |
#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.
595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/rubinius/ast/definitions.rb', line 595 def map_arguments(scope) arguments = @arguments.body while arguments node = arguments.first case node when LeftPatternVariable, PostPatternVariable, SplatPatternVariable @argument = node scope.new_local node.name scope.assign_local_reference node return end arguments = node.arguments.body end end |