class SyntaxTree::ARefField

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

Attributes

collection[R]
Node

the value being indexed

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

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 655
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 710
def ===(other)
  other.is_a?(ARefField) && collection === other.collection &&
    index === other.index
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 662
def accept(visitor)
  visitor.visit_aref_field(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 666
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 670
def copy(collection: nil, index: nil, location: nil)
  node =
    ARefField.new(
      collection: collection || self.collection,
      index: index || self.index,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end
deconstruct()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 684
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 693
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