class SyntaxTree::ARef
ARef
represents when you’re pulling a value out of a collection at a specific index. Put another way, it’s any time you’re calling the method [].
collection[index]
The nodes usually contains two children, the collection and the index. In
some cases, you don’t necessarily have the second child node, because you can call procs with a pretty esoteric syntax. In
the following example, you wouldn’t have a second child node:
collection[]
Attributes
collection[R]
Node
-
the value being indexed
index[R]
- nil |
Args
-
the value being passed within the brackets
Public Class Methods
new(collection:, index:, location:)
click to toggle source
# File lib/syntax_tree/node.rb, line 577 def initialize(collection:, index:, location:) @collection = collection @index = index @location = location @comments = [] end
Public Instance Methods
===(other)
click to toggle source
# File lib/syntax_tree/node.rb, line 632 def ===(other) other.is_a?(ARef) && collection === other.collection && index === other.index end
accept(visitor)
click to toggle source
# File lib/syntax_tree/node.rb, line 584 def accept(visitor) visitor.visit_aref(self) end
child_nodes()
click to toggle source
# File lib/syntax_tree/node.rb, line 588 def child_nodes [collection, index] end
Also aliased as: deconstruct
copy(collection: nil, index: nil, location: nil)
click to toggle source
# File lib/syntax_tree/node.rb, line 592 def copy(collection: nil, index: nil, location: nil) node = ARef.new( collection: collection || self.collection, index: index || self.index, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end
deconstruct_keys(_keys)
click to toggle source
# File lib/syntax_tree/node.rb, line 606 def deconstruct_keys(_keys) { collection: collection, index: index, location: location, comments: comments } end
format(q)
click to toggle source
# File lib/syntax_tree/node.rb, line 615 def format(q) q.group do q.format(collection) q.text("[") if index q.indent do q.breakable_empty q.format(index) end q.breakable_empty end q.text("]") end end