class RuboCop::Cop::Performance::RangeInclude
(‘a’..‘z’).cover?(‘yellow’) # => true
# the desired result:
# Example of a case where ‘Range#cover?` may not provide
(’a’..‘z’).cover?(‘b’) # => true
# good
(‘a’..‘z’).member?(‘b’) # => true
(‘a’..‘z’).include?(‘b’) # => true
# bad
@example
`Range#cover?‘ are not equivalent behaviour.
This cop is `Safe: false` by default because `Range#include?` (or `Range#member?`) and
is wanted.
end points of the `Range`. In a great majority of cases, this is what
`Range#cover?` simply compares the target item with the beginning and
item in a `Range` to see if a specified item is there. In contrast,
This cop identifies uses of `Range#include?` and `Range#member?`, which iterates over each
def on_send(node)
def on_send(node) range_include(node) do |bad_method| message = format(MSG, bad_method: bad_method) add_offense(node.loc.selector, message: message) do |corrector| corrector.replace(node.loc.selector, 'cover?') end end end