# Class: YARD::Parser::Ruby::ParameterNode

Inherits:
  AstNode
  - Object
  - Array
  - AstNode
  - YARD::Parser::Ruby::ParameterNode
  show all

Defined in:
  lib/yard/parser/ruby/ast_node.rb

## Managing node state collapse

- #args_forward ⇒ Object
- #block_param ⇒ Object
- #double_splat_param ⇒ Object
- #named_params ⇒ Object
- #splat_param ⇒ Object
- #unnamed_end_params ⇒ Object
- #unnamed_optional_params ⇒ Object
- #unnamed_required_params ⇒ Object

## Constructor Details

This class inherits a constructor from YARD::Parser::Ruby::AstNode

## Instance Method Details

### #args_forward ⇒ `Object`

    430
    431
    432
    433
    434
    435
    436

    # File 'lib/yard/parser/ruby/ast_node.rb', line 430

    def args_forward
      # shape is (required, optional, rest, more, keyword, keyword_rest, block)
      # Ruby 3.1 moves :args_forward from rest to keyword_rest
      args_index = YARD.ruby31? ? -2 : 2
      node = self[args_index]
      node.is_a?(AstNode) && node.type == :args_forward
    end

### #block_param ⇒ `Object`

    426
    427
    428

    # File 'lib/yard/parser/ruby/ast_node.rb', line 426

    def block_param
      self[-1] ? self[-1][0] : nil
    end

### #double_splat_param ⇒ `Object`

    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424

    # File 'lib/yard/parser/ruby/ast_node.rb', line 414

    def double_splat_param
      return nil unless YARD.ruby2?
      if (node = self[-2]).is_a?(AstNode)
        if node.type == :ident
          node
        elsif node.type == :kwrest_param
          # See https://bugs.ruby-lang.org/issues/12387
          node.last
        end
      end
    end

### #named_params ⇒ `Object`

    396
    397
    398
    399
    400
    401
    402
    403
    404

    # File 'lib/yard/parser/ruby/ast_node.rb', line 396

    def named_params
      return @named_params if defined?(@named_params)

      if YARD.ruby2? && self[-3] && self[-3][0] && self[-3][0].type == :named_arg
        @named_params = self[-3]
      else
        @named_params = nil
      end
    end

### #splat_param ⇒ `Object`

    406
    407
    408

    # File 'lib/yard/parser/ruby/ast_node.rb', line 406

    def splat_param
      self[2] ? self[2][0] : nil
    end

### #unnamed_end_params ⇒ `Object`

    410
    411
    412

    # File 'lib/yard/parser/ruby/ast_node.rb', line 410

    def unnamed_end_params
      self[3]
    end

### #unnamed_optional_params ⇒ `Object`

    385
    386
    387
    388
    389
    390
    391
    392
    393
    394

    # File 'lib/yard/parser/ruby/ast_node.rb', line 385

    def unnamed_optional_params
      return @unnamed_optional_params if defined?(@unnamed_optional_params)

      params = self[1] || []
      if self[-3] && self[-3][0] && self[-3][0].type == :unnamed_optional_arg
        params += self[-3]
      end

      @unnamed_optional_params = params.empty? ? nil : params
    end

### #unnamed_required_params ⇒ `Object`

    381
    382
    383

    # File 'lib/yard/parser/ruby/ast_node.rb', line 381

    def unnamed_required_params
      self[0]
    end