Module: RuboCop::AST::ParameterizedNode::RestArguments

Includes:
RuboCop::AST::ParameterizedNode
Included in:
IndexNode, IndexasgnNode, LambdaNode, SendNode
Defined in:
lib/rubocop/ast/node/mixin/parameterized_node.rb

Overview

A specialized ‘ParameterizedNode`. Requires implementing `first_argument_index` Implements `arguments` as `children` and optimizes other calls

Constant Summary collapse

EMPTY_ARGUMENTS =
[].freeze

Instance Method Summary collapse

Methods included from RuboCop::AST::ParameterizedNode

#block_argument?, #parenthesized?, #splat_argument?

Instance Method Details

#argumentsArray<Node>

Returns arguments, if any.

Returns:

  • (Array<Node>)

    arguments, if any



89
90
91
92
93
94
95
96
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 89

def arguments
  if arguments?
    children.drop(first_argument_index).freeze
  else
    # Skip unneeded Array allocation.
    EMPTY_ARGUMENTS
  end
end

#arguments?Boolean

Checks whether this node has any arguments.

Returns:

  • (Boolean)

    whether this node has any arguments



119
120
121
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 119

def arguments?
  children.size > first_argument_index
end

#first_argumentNode?

A shorthand for getting the first argument of the node. Equivalent to ‘arguments.first`.

Returns:

  • (Node, nil)

    the first argument of the node, or ‘nil` if there are no arguments



103
104
105
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 103

def first_argument
  children[first_argument_index]
end

#last_argumentNode?

A shorthand for getting the last argument of the node. Equivalent to ‘arguments.last`.

Returns:

  • (Node, nil)

    the last argument of the node, or ‘nil` if there are no arguments



112
113
114
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 112

def last_argument
  children[-1] if arguments?
end