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
OPERATOR_METHODS

phrogz.net/programmingruby/language.html#table_18.4

Public Instance Methods

assignment_method?() click to toggle source

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 44
def assignment_method?
  !comparison_method? && method_name.to_s.end_with?('=')
end
bang_method?() click to toggle source

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 66
def bang_method?
  method_name.to_s.end_with?('!')
end
camel_case_method?() click to toggle source

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 74
def camel_case_method?
  method_name.to_s =~ /\A[A-Z]/
end
comparison_method?() click to toggle source

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 37
def comparison_method?
  Node::COMPARISON_OPERATORS.include?(method_name)
end
const_receiver?() click to toggle source

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 88
def const_receiver?
  receiver&.const_type?
end
enumerator_method?() click to toggle source

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 51
def enumerator_method?
  ENUMERATOR_METHODS.include?(method_name) ||
    method_name.to_s.start_with?('each_')
end
method?(name) click to toggle source

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 23
def method?(name)
  method_name == name.to_sym
end
negation_method?() click to toggle source

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 95
def negation_method?
  receiver && method_name == :!
end
operator_method?() click to toggle source

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 30
def operator_method?
  OPERATOR_METHODS.include?(method_name)
end
predicate_method?() click to toggle source

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 59
def predicate_method?
  method_name.to_s.end_with?('?')
end
prefix_bang?() click to toggle source

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 109
def prefix_bang?
  negation_method? && loc.selector.is?('!')
end
prefix_not?() click to toggle source

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 102
def prefix_not?
  negation_method? && loc.selector.is?('not')
end
self_receiver?() click to toggle source

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 81
def self_receiver?
  receiver&.self_type?
end