class Prism::ParametersNode - Documentation for Ruby 4.1
Description: class Prism::ParametersNode: Represents the list of parameters on a method, block, or lambda definition.
Keywords: ruby,class,Prism::ParametersNode

🔍

No recent searches

# class Prism::ParametersNode

Represents the list of parameters on a method, block, or lambda definition.

    def a(b, c, d)
          ^^^^^^^
    end

### Public Class Methods

new (source, node_id, location, flags, requireds, optionals, rest, posts, keywords, keyword_rest, block)
Source

    # File lib/prism/node.rb, line 24293
    def initialize(source, node_id, location, flags, requireds, optionals, rest, posts, keywords, keyword_rest, block)
      @source = source
      @node_id = node_id
      @location = location
      @flags = flags
      @requireds = requireds
      @optionals = optionals
      @rest = rest
      @posts = posts
      @keywords = keywords
      @keyword_rest = keyword_rest
      @block = block
    end

Initialize a new `ParametersNode` node.

### Public Instance Methods

block → BlockParameterNode | NoBlockParameterNode | nil
Source

    # File lib/prism/node.rb, line 24474
    def block
      @block
    end

Returns the `block` attribute.

keyword_rest → KeywordRestParameterNode | ForwardingParameterNode | NoKeywordsParameterNode | nil
Source

    # File lib/prism/node.rb, line 24464
    def keyword_rest
      @keyword_rest
    end

Returns the `keyword_rest` attribute.

keywords → Array[RequiredKeywordParameterNode | OptionalKeywordParameterNode]
Source

    # File lib/prism/node.rb, line 24454
    def keywords
      @keywords
    end

Returns the `keywords` attribute.

optionals → Array[OptionalParameterNode]
Source

    # File lib/prism/node.rb, line 24424
    def optionals
      @optionals
    end

Returns the `optionals` attribute.

posts → Array[RequiredParameterNode | MultiTargetNode]
Source

    # File lib/prism/node.rb, line 24444
    def posts
      @posts
    end

Returns the `posts` attribute.

requireds → Array[RequiredParameterNode | MultiTargetNode]
Source

    # File lib/prism/node.rb, line 24414
    def requireds
      @requireds
    end

Returns the `requireds` attribute.

rest → RestParameterNode | ImplicitRestNode | nil
Source

    # File lib/prism/node.rb, line 24434
    def rest
      @rest
    end

Returns the `rest` attribute.

signature ()
Source

    # File lib/prism/node_ext.rb, line 315
    def signature
      names = [] #: Array[[Symbol, Symbol] | [Symbol]]

      requireds.each do |param|
        names << (param.is_a?(MultiTargetNode) ? [:req] : [:req, param.name])
      end

      optionals.each { |param| names << [:opt, param.name] }

      if (rest = self.rest).is_a?(RestParameterNode)
        names << [:rest, rest.name || :*]
      end

      posts.each do |param|
        case param
        when MultiTargetNode
          names << [:req]
        when ErrorRecoveryNode
          raise "Invalid syntax"
        else
          names << [:req, param.name]
        end
      end

      # Regardless of the order in which the keywords were defined, the required
      # keywords always come first followed by the optional keywords.
      keyopt = [] #: Array[OptionalKeywordParameterNode]
      keywords.each do |param|
        if param.is_a?(OptionalKeywordParameterNode)
          keyopt << param
        else
          names << [:keyreq, param.name]
        end
      end

      keyopt.each { |param| names << [:key, param.name] }

      case (keyword_rest = self.keyword_rest)
      when ForwardingParameterNode
        names.concat([[:rest, :*], [:keyrest, :**], [:block, :&]])
      when KeywordRestParameterNode
        names << [:keyrest, keyword_rest.name || :**]
      when NoKeywordsParameterNode
        names << [:nokey]
      end

      case (block = self.block)
      when BlockParameterNode
        names << [:block, block.name || :&]
      when NoBlockParameterNode
        names << [:noblock]
      end

      names
    end

Mirrors the `Method#parameters` method.

## Node Interface

These methods are present on all subclasses of `Node`. Read the node interface docs for more information.

### Public Class Methods

type ()
Source

    # File lib/prism/node.rb, line 24397
    def self.type
      :parameters_node
    end

See `Node.type`.

### Public Instance Methods

accept (visitor)
Source

    # File lib/prism/node.rb, line 24321
    def accept(visitor)
      visitor.visit_parameters_node(self)
    end

See `Node.accept`.

child_nodes ()
Source

    # File lib/prism/node.rb, line 24328
    def child_nodes
      [*requireds, *optionals, rest, *posts, *keywords, keyword_rest, block]
    end

See `Node.child_nodes`.

Also aliased as: deconstruct
comment_targets ()
Source

    # File lib/prism/node.rb, line 24366
    def comment_targets
      [*requireds, *optionals, *rest, *posts, *keywords, *keyword_rest, *block] #: Array[Prism::node | Location]
    end

See `Node.comment_targets`.

compact_child_nodes ()
Source

    # File lib/prism/node.rb, line 24351
    def compact_child_nodes
      compact = [] #: Array[Prism::node]
      compact.concat(requireds)
      compact.concat(optionals)
      if (rest = self.rest); compact << rest; end
      compact.concat(posts)
      compact.concat(keywords)
      if (keyword_rest = self.keyword_rest); compact << keyword_rest; end
      if (block = self.block); compact << block; end
      compact
    end

See `Node.compact_child_nodes`.

copy(**fields) → ParametersNode
Source

    # File lib/prism/node.rb, line 24376
    def copy(node_id: self.node_id, location: self.location, flags: self.flags, requireds: self.requireds, optionals: self.optionals, rest: self.rest, posts: self.posts, keywords: self.keywords, keyword_rest: self.keyword_rest, block: self.block)
      ParametersNode.new(source, node_id, location, flags, requireds, optionals, rest, posts, keywords, keyword_rest, block)
    end

Creates a copy of self with the given fields, using self as the template.

deconstruct ()
Alias for: child_nodes
each_child_node () { |node| ... }
Source

    # File lib/prism/node.rb, line 24336
    def each_child_node(&blk)
      return to_enum(:each_child_node) unless block_given?

      requireds.each { |node| yield node }
      optionals.each { |node| yield node }
      if (rest = self.rest); yield rest; end
      posts.each { |node| yield node }
      keywords.each { |node| yield node }
      if (keyword_rest = self.keyword_rest); yield keyword_rest; end
      if (block = self.block); yield block; end
    end

See `Node.each_child_node`.

type ()
Source

    # File lib/prism/node.rb, line 24390
    def type
      :parameters_node
    end

See `Node#type`.

## Repository

Methods related to `Relocation`.

## Slicing