class SyntaxTree::MLHS

MLHS represents a list of values being destructured on the left-hand side of a multiple assignment.

first, second, third = 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

parts[R]

[

Array[
  ARefField | ArgStar | ConstPathField | Field | Ident | MLHSParen |
    TopConstField | VarField
]

] the parts of the left-hand side of a multiple assignment

Public Class Methods

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

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 7693
def ===(other)
  other.is_a?(MLHS) && ArrayMatch.call(parts, other.parts) &&
    comma === other.comma
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 7662
def accept(visitor)
  visitor.visit_mlhs(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 7666
def child_nodes
  parts
end
Also aliased as: deconstruct
copy(parts: nil, location: nil, comma: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 7670
def copy(parts: nil, location: nil, comma: nil)
  node =
    MLHS.new(
      parts: parts || self.parts,
      location: location || self.location,
      comma: comma || self.comma
    )

  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 7684
def deconstruct_keys(_keys)
  { parts: parts, location: location, comma: comma, comments: comments }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 7688
def format(q)
  q.seplist(parts) { |part| q.format(part) }
  q.text(",") if comma
end