class SyntaxTree::QSymbols

QSymbols represents a symbol literal array without interpolation.

%i[one two three]

Attributes

beginning[R]
QSymbolsBeg

the token that opens this array literal

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

elements[R]
Array[ TStringContent ]

the elements of the array

Public Class Methods

new(beginning:, elements:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 8667
def initialize(beginning:, elements:, location:)
  @beginning = beginning
  @elements = elements
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 8727
def ===(other)
  other.is_a?(QSymbols) && beginning === other.beginning &&
    ArrayMatch.call(elements, other.elements)
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 8674
def accept(visitor)
  visitor.visit_qsymbols(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 8678
def child_nodes
  []
end
Also aliased as: deconstruct
copy(beginning: nil, elements: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 8682
def copy(beginning: nil, elements: nil, location: nil)
  node =
    QSymbols.new(
      beginning: beginning || self.beginning,
      elements: elements || self.elements,
      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 8696
def deconstruct_keys(_keys)
  {
    beginning: beginning,
    elements: elements,
    location: location,
    comments: comments
  }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 8705
def format(q)
  opening, closing = "%i[", "]"

  if elements.any? { |element| element.match?(/[\[\]]/) }
    opening = beginning.value
    closing = Quotes.matching(opening[2])
  end

  q.text(opening)
  q.group do
    q.indent do
      q.breakable_empty
      q.seplist(
        elements,
        ArrayLiteral::BREAKABLE_SPACE_SEPARATOR
      ) { |element| q.format(element) }
    end
    q.breakable_empty
  end
  q.text(closing)
end