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.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(collection:, index:, location:, comments: []) ⇒ ARefField
constructor
A new instance of ARefField.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(collection:, index:, location:, comments: []) ⇒ ARefField
Returns a new instance of ARefField.
507 508 509 510 511 512 |
# File 'lib/syntax_tree/node.rb', line 507 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
499 500 501 |
# File 'lib/syntax_tree/node.rb', line 499 def collection @collection end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
505 506 507 |
# File 'lib/syntax_tree/node.rb', line 505 def comments @comments end |
#index ⇒ Object (readonly)
- nil | Args
-
the value being passed within the brackets
502 503 504 |
# File 'lib/syntax_tree/node.rb', line 502 def index @index end |
Instance Method Details
#accept(visitor) ⇒ Object
514 515 516 |
# File 'lib/syntax_tree/node.rb', line 514 def accept(visitor) visitor.visit_aref_field(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
518 519 520 |
# File 'lib/syntax_tree/node.rb', line 518 def child_nodes [collection, index] end |
#deconstruct_keys(_keys) ⇒ Object
524 525 526 527 528 529 530 531 |
# File 'lib/syntax_tree/node.rb', line 524 def deconstruct_keys(_keys) { collection: collection, index: index, location: location, comments: comments } end |
#format(q) ⇒ Object
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
# File 'lib/syntax_tree/node.rb', line 533 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 |