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
-
#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.
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`.
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_argument ⇒ Node?
A shorthand for getting the first argument of the node. Equivalent to ‘arguments.first`.
24 25 26 |
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 24 def first_argument arguments[0] end |
#last_argument ⇒ Node?
A shorthand for getting the last argument of the node. Equivalent to ‘arguments.last`.
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.
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`.
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 |