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

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



86
87
88
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 86

def arguments
  children[first_argument_index..-1].freeze
end

#arguments?Boolean

Checks whether this node has any arguments.

Returns:

  • (Boolean)

    whether this node has any arguments



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

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



95
96
97
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 95

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



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

def last_argument
  children[-1] if arguments?
end