123456789_123456789_123456789_123456789_123456789_

Module: RuboCop::AST::ParameterizedNode

Relationships & Source Files
Namespace Children
Modules:
Extension / Inclusion / Inheritance Descendants
Included In:
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

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#arguments?Boolean (readonly)

Checks whether this node has any arguments.

Returns:

  • (Boolean)

    whether this node has any arguments

[ GitHub ]

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

def arguments?
  !arguments.empty?
end

#block_argument?Boolean (readonly)

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

[ GitHub ]

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

def block_argument?
  arguments? &&
    last_argument.type?(:block_pass, :blockarg)
end

#parenthesized?Boolean (readonly)

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

Returns:

  • (Boolean)

    whether this node’s arguments are wrapped in parentheses

[ GitHub ]

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

def parenthesized?
  loc_is?(:end, ')')
end

#rest_argument? (readonly)

Alias for #splat_argument?.

[ GitHub ]

  
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 52

alias rest_argument? splat_argument?

#splat_argument?Boolean (readonly) 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

[ GitHub ]

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

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

Instance Method Details

#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

[ GitHub ]

  
# 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

[ GitHub ]

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

def last_argument
  arguments[-1]
end