class RuboCop::Cop::InternalAffairs::MethodNameEqual

Checks that method names are checked using ‘method?` method.

@example

# bad
node.method_name == :do_something

# good
node.method?(:do_something)

# bad
node.method_name != :do_something

# good
!node.method?(:do_something)

Constants

MSG
RESTRICT_ON_SEND

Public Instance Methods

on_send(node) click to toggle source
# File lib/rubocop/cop/internal_affairs/method_name_equal.rb, line 35
def on_send(node)
  method_name(node) do |method_name_arg|
    bang = node.method?(:!=) ? '!' : ''
    prefer = "#{bang}#{node.receiver.receiver.source}.method?(#{method_name_arg.source})"
    message = format(MSG, prefer: prefer)

    add_offense(node, message: message) do |corrector|
      corrector.replace(node, prefer)
    end
  end
end