module RuboCop::AST::MethodIdentifierPredicates
Common predicates for nodes that reference method identifiers: `send`, `csend`, `def`, `defs`, `super`, `zsuper`
@note this mixin expects `#method_name` and `#receiver` to be implemented
Constants
- ENUMERABLE_METHODS
- ENUMERATOR_METHODS
- NONMUTATING_ARRAY_METHODS
- NONMUTATING_BINARY_OPERATOR_METHODS
- NONMUTATING_HASH_METHODS
- NONMUTATING_OPERATOR_METHODS
- NONMUTATING_STRING_METHODS
- NONMUTATING_UNARY_OPERATOR_METHODS
- OPERATOR_METHODS
Public Instance Methods
Checks whether the method is an assignment method.
@return [Boolean] whether the method is an assignment
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 142 def assignment_method? !comparison_method? && method_name.to_s.end_with?('=') end
Checks whether the method is a bang method.
@return [Boolean] whether the method is a bang method
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 171 def bang_method? method_name.to_s.end_with?('!') end
Checks whether the method is a camel case method, e.g. `Integer()`.
@return [Boolean] whether the method is a camel case method
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 179 def camel_case_method? method_name.to_s =~ /\A[A-Z]/ end
Checks whether the method is a comparison method.
@return [Boolean] whether the method is a comparison
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 135 def comparison_method? Node::COMPARISON_OPERATORS.include?(method_name) end
Checks whether the explicit receiver of node is a `const` node.
@return [Boolean] whether the receiver of this node is a `const` node
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 193 def const_receiver? receiver&.const_type? end
Checks whether the method is an Enumerable method.
@return [Boolean] whether the method is an Enumerable method
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 157 def enumerable_method? ENUMERABLE_METHODS.include?(method_name) end
Checks whether the method is an enumerator method.
@return [Boolean] whether the method is an enumerator
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 149 def enumerator_method? ENUMERATOR_METHODS.include?(method_name) || method_name.to_s.start_with?('each_') end
Checks whether the method name matches the argument.
@param [Symbol, String] name the method name to check for @return [Boolean] whether the method name matches the argument
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 79 def method?(name) method_name == name.to_sym end
Checks whether this is a negation method, i.e. `!` or keyword `not`.
@return [Boolean] whether this method is a negation method
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 200 def negation_method? receiver && method_name == :! end
Checks whether the method is a nonmutating Array method.
@return [Boolean] whether the method is a nonmutating Array method
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 114 def nonmutating_array_method? NONMUTATING_ARRAY_METHODS.include?(method_name) end
Checks whether the method is a nonmutating binary operator method.
@return [Boolean] whether the method is a nonmutating binary operator method
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 93 def nonmutating_binary_operator_method? NONMUTATING_BINARY_OPERATOR_METHODS.include?(method_name) end
Checks whether the method is a nonmutating Hash method.
@return [Boolean] whether the method is a nonmutating Hash method
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 121 def nonmutating_hash_method? NONMUTATING_HASH_METHODS.include?(method_name) end
Checks whether the method is a nonmutating operator method.
@return [Boolean] whether the method is a nonmutating operator method
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 107 def nonmutating_operator_method? NONMUTATING_OPERATOR_METHODS.include?(method_name) end
Checks whether the method is a nonmutating String method.
@return [Boolean] whether the method is a nonmutating String method
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 128 def nonmutating_string_method? NONMUTATING_STRING_METHODS.include?(method_name) end
Checks whether the method is a nonmutating unary operator method.
@return [Boolean] whether the method is a nonmutating unary operator method
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 100 def nonmutating_unary_operator_method? NONMUTATING_UNARY_OPERATOR_METHODS.include?(method_name) end
Checks whether the method is an operator method.
@return [Boolean] whether the method is an operator
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 86 def operator_method? OPERATOR_METHODS.include?(method_name) end
Checks whether the method is a predicate method.
@return [Boolean] whether the method is a predicate method
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 164 def predicate_method? method_name.to_s.end_with?('?') end
Checks whether this is a prefix bang method, e.g. `!foo`.
@return [Boolean] whether this method is a prefix bang
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 214 def prefix_bang? negation_method? && loc.selector.is?('!') end
Checks whether this is a prefix not method, e.g. `not foo`.
@return [Boolean] whether this method is a prefix not
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 207 def prefix_not? negation_method? && loc.selector.is?('not') end
Checks whether the explicit receiver of this node is `self`.
@return [Boolean] whether the receiver of this node is `self`
# File lib/rubocop/ast/node/mixin/method_identifier_predicates.rb, line 186 def self_receiver? receiver&.self_type? end