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
-
#arguments? ⇒ Boolean
readonly
Checks whether this node has any arguments.
-
#block_argument? ⇒ Boolean
readonly
Whether the last argument of the node is a block pass, i.e.
-
#parenthesized? ⇒ Boolean
readonly
Checks whether this node’s arguments are wrapped in parentheses.
-
#rest_argument?
readonly
Alias for #splat_argument?.
-
#splat_argument? ⇒ Boolean
(also: #rest_argument?)
readonly
Checks whether any argument of the node is a splat argument, i.e.
Instance Method Summary
-
#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.
Instance Attribute Details
#arguments? ⇒ Boolean
(readonly)
Checks whether this node has any arguments.
# 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
.
# 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.
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 15
def parenthesized? loc_is?(:end, ')') end
#rest_argument? (readonly)
Alias for #splat_argument?.
# 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
.
# 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_argument ⇒ Node?
A shorthand for getting the first argument of the node.
Equivalent to arguments.first
.
# 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
.
# File 'lib/rubocop/ast/node/mixin/parameterized_node.rb', line 33
def last_argument arguments[-1] end