Module: RuboCop::AST::MethodIdentifierPredicates
- Included in:
- DefNode, MethodDispatchNode
- Defined in:
- lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
Overview
this mixin expects ‘#method_name` and `#receiver` to be implemented
Common predicates for nodes that reference method identifiers: ‘send`, `csend`, `def`, `defs`, `super`, `zsuper`
Constant Summary collapse
- ENUMERATOR_METHODS =
%i[collect collect_concat detect downto each find find_all find_index inject loop map! map reduce reject reject! reverse_each select select! times upto].freeze
- OPERATOR_METHODS =
%i[| ^ & <=> == === =~ > >= < <= << >> + - * / % ** ~ +@ -@ !@ ~@ [] []= ! != !~ `].freeze
Instance Method Summary collapse
-
#assignment_method? ⇒ Boolean
Checks whether the method is an assignment method.
-
#bang_method? ⇒ Boolean
Checks whether the method is a bang method.
-
#camel_case_method? ⇒ Boolean
Checks whether the method is a camel case method, e.g.
-
#comparison_method? ⇒ Boolean
Checks whether the method is a comparison method.
-
#const_receiver? ⇒ Boolean
Checks whether the explicit receiver of node is a ‘const` node.
-
#enumerator_method? ⇒ Boolean
Checks whether the method is an enumerator method.
-
#method?(name) ⇒ Boolean
Checks whether the method name matches the argument.
-
#negation_method? ⇒ Boolean
Checks whether this is a negation method, i.e.
-
#operator_method? ⇒ Boolean
Checks whether the method is an operator method.
-
#predicate_method? ⇒ Boolean
Checks whether the method is a predicate method.
-
#prefix_bang? ⇒ Boolean
Checks whether this is a prefix bang method, e.g.
-
#prefix_not? ⇒ Boolean
Checks whether this is a prefix not method, e.g.
-
#self_receiver? ⇒ Boolean
Checks whether the explicit receiver of this node is ‘self`.
Instance Method Details
#assignment_method? ⇒ Boolean
Checks whether the method is an assignment method.
44 45 46 |
# File 'lib/rubocop/ast/node/mixin/method_identifier_predicates.rb', line 44 def assignment_method? !comparison_method? && method_name.to_s.end_with?('=') end |
#bang_method? ⇒ Boolean
Checks whether the method is a bang method.
66 67 68 |
# File 'lib/rubocop/ast/node/mixin/method_identifier_predicates.rb', line 66 def bang_method? method_name.to_s.end_with?('!') end |
#camel_case_method? ⇒ Boolean
Checks whether the method is a camel case method, e.g. ‘Integer()`.
74 75 76 |
# File 'lib/rubocop/ast/node/mixin/method_identifier_predicates.rb', line 74 def camel_case_method? method_name.to_s =~ /\A[A-Z]/ end |
#comparison_method? ⇒ Boolean
Checks whether the method is a comparison method.
37 38 39 |
# File 'lib/rubocop/ast/node/mixin/method_identifier_predicates.rb', line 37 def comparison_method? Node::COMPARISON_OPERATORS.include?(method_name) end |
#const_receiver? ⇒ Boolean
Checks whether the explicit receiver of node is a ‘const` node.
88 89 90 |
# File 'lib/rubocop/ast/node/mixin/method_identifier_predicates.rb', line 88 def const_receiver? receiver&.const_type? end |
#enumerator_method? ⇒ Boolean
Checks whether the method is an enumerator method.
51 52 53 54 |
# File 'lib/rubocop/ast/node/mixin/method_identifier_predicates.rb', line 51 def enumerator_method? ENUMERATOR_METHODS.include?(method_name) || method_name.to_s.start_with?('each_') end |
#method?(name) ⇒ Boolean
Checks whether the method name matches the argument.
23 24 25 |
# File 'lib/rubocop/ast/node/mixin/method_identifier_predicates.rb', line 23 def method?(name) method_name == name.to_sym end |
#negation_method? ⇒ Boolean
Checks whether this is a negation method, i.e. ‘!` or keyword `not`.
95 96 97 |
# File 'lib/rubocop/ast/node/mixin/method_identifier_predicates.rb', line 95 def negation_method? receiver && method_name == :! end |
#operator_method? ⇒ Boolean
Checks whether the method is an operator method.
30 31 32 |
# File 'lib/rubocop/ast/node/mixin/method_identifier_predicates.rb', line 30 def operator_method? OPERATOR_METHODS.include?(method_name) end |
#predicate_method? ⇒ Boolean
Checks whether the method is a predicate method.
59 60 61 |
# File 'lib/rubocop/ast/node/mixin/method_identifier_predicates.rb', line 59 def predicate_method? method_name.to_s.end_with?('?') end |
#prefix_bang? ⇒ Boolean
Checks whether this is a prefix bang method, e.g. ‘!foo`.
109 110 111 |
# File 'lib/rubocop/ast/node/mixin/method_identifier_predicates.rb', line 109 def prefix_bang? negation_method? && loc.selector.is?('!') end |
#prefix_not? ⇒ Boolean
Checks whether this is a prefix not method, e.g. ‘not foo`.
102 103 104 |
# File 'lib/rubocop/ast/node/mixin/method_identifier_predicates.rb', line 102 def prefix_not? negation_method? && loc.selector.is?('not') end |
#self_receiver? ⇒ Boolean
Checks whether the explicit receiver of this node is ‘self`.
81 82 83 |
# File 'lib/rubocop/ast/node/mixin/method_identifier_predicates.rb', line 81 def self_receiver? receiver&.self_type? end |