class SyntaxTree::FndPtn

FndPtn represents matching against a pattern where you find a pattern in an array using the Ruby 3.0+ pattern matching syntax.

case value
in [*, 7, *]
end

Attributes

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

constant[R]
nil | VarRef | ConstPathRef

the optional constant wrapper

left[R]
VarField

the splat on the left-hand side

right[R]
VarField

the splat on the right-hand side

values[R]
Array[ Node ]

the list of positional expressions in the pattern that

are being matched

Public Class Methods

new(constant:, left:, values:, right:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 5435
def initialize(constant:, left:, values:, right:, location:)
  @constant = constant
  @left = left
  @values = values
  @right = right
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 5504
def ===(other)
  other.is_a?(FndPtn) && constant === other.constant &&
    left === other.left && ArrayMatch.call(values, other.values) &&
    right === other.right
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 5444
def accept(visitor)
  visitor.visit_fndptn(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 5448
def child_nodes
  [constant, left, *values, right]
end
Also aliased as: deconstruct
copy(constant: nil, left: nil, values: nil, right: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 5452
def copy(constant: nil, left: nil, values: nil, right: nil, location: nil)
  node =
    FndPtn.new(
      constant: constant || self.constant,
      left: left || self.left,
      values: values || self.values,
      right: right || self.right,
      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 5468
def deconstruct_keys(_keys)
  {
    constant: constant,
    left: left,
    values: values,
    right: right,
    location: location,
    comments: comments
  }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 5479
def format(q)
  q.format(constant) if constant

  q.group do
    q.text("[")

    q.indent do
      q.breakable_empty

      q.text("*")
      q.format(left)
      q.comma_breakable

      q.seplist(values) { |value| q.format(value) }
      q.comma_breakable

      q.text("*")
      q.format(right)
    end

    q.breakable_empty
    q.text("]")
  end
end