A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://ruby-syntax-tree.github.io/syntax_tree/SyntaxTree/AryPtn.html below:

class SyntaxTree::AryPtn - RDoc Documentation

  1. SyntaxTree::
  2. AryPtn
class SyntaxTree::AryPtn

AryPtn represents matching against an array pattern using the Ruby 2.7+ pattern matching syntax. It’s one of the more complicated nodes, because the four parameters that it accepts can almost all be nil.

case [1, 2, 3]
in [Integer, Integer]
  "matched"
in Container[Integer, Integer]
  "matched"
in [Integer, *, Integer]
  "matched"
end

An AryPtn node is created with four parameters: an optional constant wrapper, an array of positional matches, an optional splat with identifier, and an optional array of positional matches that occur after the splat. All of the in clauses above would create an AryPtn node.

Attributes
Array[ Node ]

the list of positional arguments occurring after the

optional star if there is one

Array[ Node ]

the regular positional arguments that this array

pattern is matching against

nil | VarField

the optional starred identifier that grabs up a list of

positional arguments

Public Class Methods

Source

def initialize(constant:, requireds:, rest:, posts:, location:)
  @constant = constant
  @requireds = requireds
  @rest = rest
  @posts = posts
  @location = location
  @comments = []
end
Public Instance Methods

Source

def ===(other)
  other.is_a?(AryPtn) && constant === other.constant &&
    ArrayMatch.call(requireds, other.requireds) && rest === other.rest &&
    ArrayMatch.call(posts, other.posts)
end

Source

def accept(visitor)
  visitor.visit_aryptn(self)
end

Source

def child_nodes
  [constant, *requireds, rest, *posts]
end

Source

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

Source

def deconstruct_keys(_keys)
  {
    constant: constant,
    requireds: requireds,
    rest: rest,
    posts: posts,
    location: location,
    comments: comments
  }
end

Source

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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4