class RubbyCop::Cop::Performance::RangeInclude

This cop identifies uses of `Range#include?`, which iterates over each item in a `Range` to see if a specified item is there. In contrast, `Range#cover?` simply compares the target item with the beginning and end points of the `Range`. In a great majority of cases, this is what is wanted.

Here is an example of a case where `Range#cover?` may not provide the desired result:

('a'..'z').cover?('yellow') # => true

Constants

MSG

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubbycop/cop/performance/range_include.rb, line 35
def autocorrect(node)
  ->(corrector) { corrector.replace(node.loc.selector, 'cover?') }
end
on_send(node) click to toggle source
# File lib/rubbycop/cop/performance/range_include.rb, line 29
def on_send(node)
  return unless range_include(node)

  add_offense(node, :selector)
end