Class: SyntaxTree::ARefField
Overview
ARefField represents assigning values into collections at specific indices. Put another way, it’s any time you’re calling the method #[]=. The ARefField node itself is just the left side of the assignment, and they’re always wrapped in assign nodes.
collection[index] = value
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
- untyped
-
the value being indexed.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#index ⇒ Object
readonly
- nil | Args
-
the value being passed within the brackets.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(collection:, index:, location:, comments: []) ⇒ ARefField
constructor
A new instance of ARefField.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(collection:, index:, location:, comments: []) ⇒ ARefField
Returns a new instance of ARefField.
577 578 579 580 581 582 |
# File 'lib/syntax_tree/node.rb', line 577 def initialize(collection:, index:, location:, comments: []) @collection = collection @index = index @location = location @comments = comments end |
Instance Attribute Details
#collection ⇒ Object (readonly)
- untyped
-
the value being indexed
566 567 568 |
# File 'lib/syntax_tree/node.rb', line 566 def collection @collection end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
575 576 577 |
# File 'lib/syntax_tree/node.rb', line 575 def comments @comments end |
#index ⇒ Object (readonly)
- nil | Args
-
the value being passed within the brackets
569 570 571 |
# File 'lib/syntax_tree/node.rb', line 569 def index @index end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
572 573 574 |
# File 'lib/syntax_tree/node.rb', line 572 def location @location end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
584 585 586 |
# File 'lib/syntax_tree/node.rb', line 584 def child_nodes [collection, index] end |
#deconstruct_keys(keys) ⇒ Object
590 591 592 593 594 595 596 597 |
# File 'lib/syntax_tree/node.rb', line 590 def deconstruct_keys(keys) { collection: collection, index: index, location: location, comments: comments } end |
#format(q) ⇒ Object
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'lib/syntax_tree/node.rb', line 599 def format(q) q.group do q.format(collection) q.text("[") if index q.indent do q.breakable("") q.format(index) end q.breakable("") end q.text("]") end end |
#pretty_print(q) ⇒ Object
616 617 618 619 620 621 622 623 624 625 626 627 628 |
# File 'lib/syntax_tree/node.rb', line 616 def pretty_print(q) q.group(2, "(", ")") do q.text("aref_field") q.breakable q.pp(collection) q.breakable q.pp(index) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
630 631 632 633 634 635 636 637 638 |
# File 'lib/syntax_tree/node.rb', line 630 def to_json(*opts) { type: :aref_field, collection: collection, index: index, loc: location, cmts: comments }.to_json(*opts) end |