Module: RuboCop::AST::ParameterizedNode

Included in:
DefNode, DefinedNode, RestArguments, WrappedArguments, SuperNode, YieldNode
Defined in:
lib/rubocop/ast/node/mixin/parameterized_node.rb

Overview

Requires implementing ‘arguments`.

Common functionality for nodes that are parameterized: ‘send`, `super`, `zsuper`, `def`, `defs` and (modern only): `index`, `indexasgn`, `lambda`

Defined Under Namespace

Modules: RestArguments, WrappedArguments

Instance Method Summary collapse

Instance Method Details

#arguments?Boolean

Checks whether this node has any arguments.

Returns:

  • (Boolean)

    whether this node has any arguments



40
41
42
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 40

def arguments?
  !arguments.empty?
end

#block_argument?Boolean

Whether the last argument of the node is a block pass, i.e. ‘&block`.

Returns:

  • (Boolean)

    whether the last argument of the node is a block pass



58
59
60
61
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 58

def block_argument?
  arguments? &&
    (last_argument.block_pass_type? || last_argument.blockarg_type?)
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



24
25
26
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 24

def first_argument
  arguments[0]
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



33
34
35
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 33

def last_argument
  arguments[-1]
end

#parenthesized?Boolean

Checks whether this node’s arguments are wrapped in parentheses.

Returns:

  • (Boolean)

    whether this node’s arguments are wrapped in parentheses



15
16
17
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 15

def parenthesized?
  loc.end&.is?(')')
end

#splat_argument?Boolean Also known as: rest_argument?

Checks whether any argument of the node is a splat argument, i.e. ‘*splat`.

Returns:

  • (Boolean)

    whether the node is a splat argument



48
49
50
51
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 48

def splat_argument?
  arguments? &&
    (arguments.any?(&:splat_type?) || arguments.any?(&:restarg_type?))
end