Module: RuboCop::AST::ParameterizedNode
- 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
-
#arguments? ⇒ Boolean
Checks whether this node has any arguments.
-
#block_argument? ⇒ Boolean
Whether the last argument of the node is a block pass, i.e.
-
#first_argument ⇒ Node?
A shorthand for getting the first argument of the node.
-
#last_argument ⇒ Node?
A shorthand for getting the last argument of the node.
-
#parenthesized? ⇒ Boolean
Checks whether this node’s arguments are wrapped in parentheses.
-
#splat_argument? ⇒ Boolean
(also: #rest_argument?)
Checks whether any argument of the node is a splat argument, i.e.
Instance Method Details
#arguments? ⇒ Boolean
Checks 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`.
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_argument ⇒ Node?
A shorthand for getting the first argument of the node. Equivalent to ‘arguments.first`.
21 22 23 |
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 21 def first_argument arguments[0] end |
#last_argument ⇒ Node?
A shorthand for getting the last argument of the node. Equivalent to ‘arguments.last`.
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.
12 13 14 |
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 12 def parenthesized? loc.end && 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`.
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 |