class SyntaxTree::Words

Words represents a string literal array with interpolation.

%W[one two three]

Attributes

beginning[R]
WordsBeg

the token that opens this array literal

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

elements[R]
Array[ Word ]

the elements of this array

Public Class Methods

new(beginning:, elements:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 12070
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 12126
def ===(other)
  other.is_a?(Words) && beginning === other.beginning &&
    ArrayMatch.call(elements, other.elements)
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 12077
def accept(visitor)
  visitor.visit_words(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 12081
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 12085
def copy(beginning: nil, elements: nil, location: nil)
  Words.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 12095
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 12104
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