Module: RuboCop::AST::ParameterizedNode
Overview
Common functionality for nodes that are parameterized: ‘send`, `super`, `zsuper` …
Instance Method Summary collapse
-
#arguments? ⇒ Boolean
Checks whether this method was invoked with arguments.
-
#block_argument? ⇒ Boolean
Whether the last argument of the method invocation is a block pass, i.e.
-
#block_literal? ⇒ Boolean
Whether this method invocation has an explicit block.
-
#block_node ⇒ BlockNode?
The block node associated with this method call, if any.
-
#first_argument ⇒ Node?
A shorthand for getting the first argument of the method invocation.
-
#last_argument ⇒ Node?
A shorthand for getting the last argument of the method invocation.
-
#parenthesized? ⇒ Boolean
Checks whether this super invocation’s arguments are wrapped in parentheses.
-
#splat_argument? ⇒ Boolean
Checks whether any argument of the method invocation is a splat argument, i.e.
Instance Method Details
#arguments? ⇒ Boolean
Checks 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`.
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.
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_node ⇒ BlockNode?
The block node associated with this method call, if any.
69 70 71 |
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 69 def block_node parent if block_literal? end |
#first_argument ⇒ Node?
A shorthand for getting the first argument of the method invocation. Equivalent to ‘arguments.first`.
22 23 24 |
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 22 def first_argument arguments[0] end |
#last_argument ⇒ Node?
A shorthand for getting the last argument of the method invocation. Equivalent to ‘arguments.last`.
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.
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`.
46 47 48 |
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 46 def splat_argument? arguments? && arguments.any?(&:splat_type?) end |