Class: RuboCop::Cop::Performance::RangeInclude
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
AutoCorrector,
Base
|
|
Instance Chain:
self,
Base
|
|
Inherits: |
Base
|
Defined in: | lib/rubocop/cop/performance/range_include.rb |
Overview
Identifies uses of Range#include?
and Range#member?
, 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.
Constant Summary
-
MSG =
# File 'lib/rubocop/cop/performance/range_include.rb', line 32'Use `Range#cover?` instead of `Range#%<bad_method>s`.'
-
RESTRICT_ON_SEND =
# File 'lib/rubocop/cop/performance/range_include.rb', line 33%i[include? member?].freeze
Instance Method Summary
-
#on_csend(node)
Alias for #on_send.
- #on_send(node) (also: #on_csend)
Instance Method Details
#on_csend(node)
Alias for #on_send.
# File 'lib/rubocop/cop/performance/range_include.rb', line 53
alias on_csend on_send
#on_send(node) Also known as: #on_csend
[ GitHub ]# File 'lib/rubocop/cop/performance/range_include.rb', line 44
def on_send(node) range_include(node) do |bad_method| = format(MSG, bad_method: bad_method) add_offense(node.loc.selector, message: ) do |corrector| corrector.replace(node.loc.selector, 'cover?') end end end