class SyntaxTree::MLHSParen

MLHSParen represents parentheses being used to destruct values in a multiple assignment on the left hand side.

(left, right) = value

Attributes

comma[RW]
boolean

whether or not there is a trailing comma at the end of this

list, which impacts destructuring. It’s an attr_accessor so that while the syntax tree is being built it can be set by its parent node

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

contents[R]
MLHS | MLHSParen

the contents inside of the parentheses

Public Class Methods

new(contents:, location:, comma: false) click to toggle source
# File lib/syntax_tree/node.rb, line 7716
def initialize(contents:, location:, comma: false)
  @contents = contents
  @comma = comma
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 7769
def ===(other)
  other.is_a?(MLHSParen) && contents === other.contents
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 7723
def accept(visitor)
  visitor.visit_mlhs_paren(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 7727
def child_nodes
  [contents]
end
Also aliased as: deconstruct
copy(contents: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 7731
def copy(contents: nil, location: nil)
  node =
    MLHSParen.new(
      contents: contents || self.contents,
      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 7744
def deconstruct_keys(_keys)
  { contents: contents, location: location, comments: comments }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 7748
def format(q)
  parent = q.parent

  if parent.is_a?(MAssign) || parent.is_a?(MLHSParen)
    q.format(contents)
    q.text(",") if comma
  else
    q.text("(")
    q.group do
      q.indent do
        q.breakable_empty
        q.format(contents)
      end

      q.text(",") if comma
      q.breakable_empty
    end
    q.text(")")
  end
end