class SyntaxTree::AryPtn
All of the in clauses above would create an AryPtn node.
and an optional array of positional matches that occur after the splat.
wrapper, an array of positional matches, an optional splat with identifier,
An AryPtn node is created with four parameters: an optional constant
end
“matched”
in [Integer, *, Integer]
“matched”
in Container[Integer, Integer]
“matched”
in [Integer, Integer]
case [1, 2, 3]
the four parameters that it accepts can almost all be nil.
pattern matching syntax. It’s one of the more complicated nodes, because
AryPtn represents matching against an array pattern using the Ruby 2.7+
def ===(other)
def ===(other) other.is_a?(AryPtn) && constant === other.constant && ArrayMatch.call(requireds, other.requireds) && rest === other.rest && ArrayMatch.call(posts, other.posts) end
def accept(visitor)
def accept(visitor) visitor.visit_aryptn(self) end
def child_nodes
def child_nodes [constant, *requireds, rest, *posts] end
def copy(
def copy( constant: nil, requireds: nil, rest: nil, posts: nil, location: nil ) node = AryPtn.new( constant: constant || self.constant, requireds: requireds || self.requireds, rest: rest || self.rest, posts: posts || self.posts, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end
def deconstruct_keys(_keys)
def deconstruct_keys(_keys) { constant: constant, requireds: requireds, rest: rest, posts: posts, location: location, comments: comments } end
def format(q)
def format(q) q.group do q.format(constant) if constant q.text("[") q.indent do q.breakable_empty parts = [*requireds] parts << RestFormatter.new(rest) if rest parts += posts q.seplist(parts) { |part| q.format(part) } end q.breakable_empty q.text("]") end end
def initialize(constant:, requireds:, rest:, posts:, location:)
def initialize(constant:, requireds:, rest:, posts:, location:) @constant = constant @requireds = requireds @rest = rest @posts = posts @location = location @comments = [] end