class SyntaxTree::QWords

QWords represents a string literal array without interpolation.

%w[one two three]

Attributes

beginning[R]
QWordsBeg

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 8789
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 8845
def ===(other)
  other.is_a?(QWords) && beginning === other.beginning &&
    ArrayMatch.call(elements, other.elements)
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 8796
def accept(visitor)
  visitor.visit_qwords(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 8800
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 8804
def copy(beginning: nil, elements: nil, location: nil)
  QWords.new(
    beginning: beginning || self.beginning,
    elements: elements || self.elements,
    location: location || self.location
  )
end
deconstruct()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 8814
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 8823
def format(q)
  opening, closing = "%w[", "]"

  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