class RuboCop::Cop::Rails::NegateInclude
hash.exclude?(:key)
array.exclude?(2)
# good
!hash.include?(:key)
!array.include?(2)
# bad
@example
a receiver object that do not have ‘exclude?` method. (e.g. `IPAddr`)
It is marked as unsafe by default because false positive will occur for
over `!collection.include?(obj)`.
This cop enforces the use of `collection.exclude?(obj)`
def on_send(node)
def on_send(node) return unless (receiver, obj = negate_include_call?(node)) add_offense(node) do |corrector| corrector.replace(node, "#{receiver.source}.exclude?(#{obj.source})") end end