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
- ENUMERATOR_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 40 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 62 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 70 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 33 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 84 def const_receiver? receiver && receiver.const_type? 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 47 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 19 def method?(name) method_name == name.to_sym 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 26 def operator_method? RuboCop::Cop::Util::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 55 def predicate_method? method_name.to_s.end_with?('?') 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 77 def self_receiver? receiver && receiver.self_type? end