Module: RuboCop::AST::ParameterizedNode

Included in:
SendNode, SuperNode
Defined in:
lib/rubocop/ast/node/mixin/parameterized_node.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#arguments?Boolean

Checks whether this method was invoked with arguments.

Returns:

  • (Boolean)

    whether this method was invoked with arguments



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

def arguments?
  !arguments.empty?
end

#block_argument?Boolean

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

Returns:

  • (Boolean)

    whether the invoked method is a block pass



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

def block_argument?
  arguments? && last_argument.block_pass_type?
end

#block_literal?Boolean

Whether this method invocation has an explicit block.

Returns:

  • (Boolean)

    whether the invoked method has a block



61
62
63
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 61

def block_literal?
  parent && parent.block_type? && eql?(parent.send_node)
end

#block_nodeBlockNode?

The block node associated with this method call, if any.

Returns:

  • (BlockNode, nil)

    the ‘block` node associated with this method call or `nil`



69
70
71
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 69

def block_node
  parent if block_literal?
end

#first_argumentNode?

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

Returns:

  • (Node, nil)

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



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

def first_argument
  arguments[0]
end

#last_argumentNode?

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

Returns:

  • (Node, nil)

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



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

def last_argument
  arguments[-1]
end

#parenthesized?Boolean

Checks whether this super invocation’s arguments are wrapped in parentheses.

Returns:

  • (Boolean)

    whether this super invocation’s arguments are wrapped in parentheses



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

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

#splat_argument?Boolean

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

Returns:

  • (Boolean)

    whether the invoked method is a splat argument



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

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