class RuboCop::Cop::Rails::NegateInclude
This cop enforces the use of `collection.exclude?(obj)` over `!collection.include?(obj)`.
It is marked as unsafe by default because false positive will occur for a receiver object that do not have `exclude?` method. (e.g. `IPAddr`)
@example
# bad !array.include?(2) !hash.include?(:key) # good array.exclude?(2) hash.exclude?(:key)
Constants
- MSG
- RESTRICT_ON_SEND
Public Instance Methods
on_send(node)
click to toggle source
# File lib/rubocop/cop/rails/negate_include.rb, line 31 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