Module: RuboCop::AST::ParameterizedNode

Included in:
BreakNode, DefNode, DefinedNode, RetryNode, ReturnNode, SendNode, SuperNode, YieldNode
Defined in:
lib/rubocop/ast/node/mixin/parameterized_node.rb

Overview

Common functionality for nodes that are parameterized: ‘send`, `super`, `zsuper`, `def`, `defs`

Instance Method Summary collapse

Instance Method Details

#arguments?Boolean

Checks whether this node has any arguments.

Returns:

  • (Boolean)

    whether this node has any arguments



37
38
39
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 37

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



55
56
57
58
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 55

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



21
22
23
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 21

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



30
31
32
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 30

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



12
13
14
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 12

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



45
46
47
48
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 45

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