Module: RuboCop::AST::MethodDispatchNode
- Extended by:
- NodePattern::Macros
- Includes:
- MethodIdentifierPredicates
- Defined in:
- lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Overview
Common functionality for nodes that are a kind of method dispatch: ‘send`, `csend`, `super`, `zsuper`, `yield`
Constant Summary
Constants included from MethodIdentifierPredicates
RuboCop::AST::MethodIdentifierPredicates::ENUMERATOR_METHODS
Instance Method Summary collapse
-
#access_modifier? ⇒ Boolean
Checks whether the dispatched method is a bare access modifier affects all methods defined after the macro.
-
#arguments ⇒ Array<Node>
An array containing the arguments of the dispatched method.
-
#block_literal? ⇒ Boolean
Whether this method dispatch has an explicit block.
-
#block_node ⇒ BlockNode?
The ‘block` node associated with this method dispatch, if any.
-
#command?(name) ⇒ Boolean
Checks whether the name of the dispatched method matches the argument and has an implicit receiver.
-
#const_receiver? ⇒ Boolean
Checks whether the explicit receiver of this method dispatch is a ‘const` node.
-
#def_modifier? ⇒ Boolean
Checks if this node is part of a chain of ‘def` modifiers.
-
#dot? ⇒ Boolean
Checks whether the dispatched method uses a dot to connect the receiver and the method name.
-
#double_colon? ⇒ Boolean
Checks whether the dispatched method uses a double colon to connect the receiver and the method name.
-
#implicit_call? ⇒ Boolean
Checks whether the method dispatch is the implicit form of ‘#call`, e.g.
-
#macro? ⇒ Boolean
Checks whether the dispatched method is a macro method.
-
#method_name ⇒ Symbol
The name of the dispatched method as a symbol.
-
#receiver ⇒ Node?
The receiving node of the method dispatch.
-
#self_receiver? ⇒ Boolean
Checks whether the explicit receiver of this method dispatch is ‘self`.
-
#setter_method? ⇒ Boolean
Checks whether the dispatched method is a setter method.
Methods included from NodePattern::Macros
def_node_matcher, def_node_search, node_search, node_search_all, node_search_body, node_search_first
Methods included from MethodIdentifierPredicates
#assignment_method?, #bang_method?, #camel_case_method?, #comparison_method?, #enumerator_method?, #method?, #operator_method?, #predicate_method?
Instance Method Details
#access_modifier? ⇒ Boolean
Checks whether the dispatched method is a bare access modifier affects all methods defined after the macro.
47 48 49 |
# File 'lib/rubocop/ast/node/mixin/method_dispatch_node.rb', line 47 def access_modifier? macro? && end |
#arguments ⇒ Array<Node>
An array containing the arguments of the dispatched method.
28 29 30 |
# File 'lib/rubocop/ast/node/mixin/method_dispatch_node.rb', line 28 def arguments node_parts[2..-1] end |
#block_literal? ⇒ Boolean
Whether this method dispatch has an explicit block.
114 115 116 |
# File 'lib/rubocop/ast/node/mixin/method_dispatch_node.rb', line 114 def block_literal? parent && parent.block_type? && eql?(parent.send_node) end |
#block_node ⇒ BlockNode?
The ‘block` node associated with this method dispatch, if any.
122 123 124 |
# File 'lib/rubocop/ast/node/mixin/method_dispatch_node.rb', line 122 def block_node parent if block_literal? end |
#command?(name) ⇒ Boolean
Checks whether the name of the dispatched method matches the argument and has an implicit receiver.
56 57 58 |
# File 'lib/rubocop/ast/node/mixin/method_dispatch_node.rb', line 56 def command?(name) !receiver && method?(name) end |
#const_receiver? ⇒ Boolean
Checks whether the explicit receiver of this method dispatch is a ‘const` node.
99 100 101 |
# File 'lib/rubocop/ast/node/mixin/method_dispatch_node.rb', line 99 def const_receiver? receiver && receiver.const_type? end |
#def_modifier? ⇒ Boolean
Checks if this node is part of a chain of ‘def` modifiers.
133 134 135 136 |
# File 'lib/rubocop/ast/node/mixin/method_dispatch_node.rb', line 133 def def_modifier? send_type? && [self, *each_descendant(:send)].any?(&:adjacent_def_modifier?) end |
#dot? ⇒ Boolean
Checks whether the dispatched method uses a dot to connect the receiver and the method name.
This is useful for comparison operators, which can be called either with or without a dot, i.e. ‘foo == bar` or `foo.== bar`.
74 75 76 |
# File 'lib/rubocop/ast/node/mixin/method_dispatch_node.rb', line 74 def dot? loc.respond_to?(:dot) && loc.dot && loc.dot.is?('.') end |
#double_colon? ⇒ Boolean
Checks whether the dispatched method uses a double colon to connect the receiver and the method name.
82 83 84 |
# File 'lib/rubocop/ast/node/mixin/method_dispatch_node.rb', line 82 def double_colon? loc.respond_to?(:dot) && loc.dot && loc.dot.is?('::') end |
#implicit_call? ⇒ Boolean
Checks whether the method dispatch is the implicit form of ‘#call`, e.g. `foo.(bar)`.
107 108 109 |
# File 'lib/rubocop/ast/node/mixin/method_dispatch_node.rb', line 107 def implicit_call? method?(:call) && !loc.selector end |
#macro? ⇒ Boolean
This does not include DSLs that use nested blocks, like RSpec
Checks whether the dispatched method is a macro method. A macro method is defined as a method that sits in a class, module, or block body and has an implicit receiver.
39 40 41 |
# File 'lib/rubocop/ast/node/mixin/method_dispatch_node.rb', line 39 def macro? !receiver && macro_scope? end |
#method_name ⇒ Symbol
The name of the dispatched method as a symbol.
21 22 23 |
# File 'lib/rubocop/ast/node/mixin/method_dispatch_node.rb', line 21 def method_name node_parts[1] end |
#receiver ⇒ Node?
The receiving node of the method dispatch.
14 15 16 |
# File 'lib/rubocop/ast/node/mixin/method_dispatch_node.rb', line 14 def receiver node_parts[0] end |
#self_receiver? ⇒ Boolean
Checks whether the explicit receiver of this method dispatch is ‘self`.
90 91 92 |
# File 'lib/rubocop/ast/node/mixin/method_dispatch_node.rb', line 90 def self_receiver? receiver && receiver.self_type? end |
#setter_method? ⇒ Boolean
Checks whether the dispatched method is a setter method.
63 64 65 |
# File 'lib/rubocop/ast/node/mixin/method_dispatch_node.rb', line 63 def setter_method? loc.respond_to?(:operator) && loc.operator end |