Class: RuboCop::Cop::Performance::RedundantMatch
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Performance::RedundantMatch
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/performance/redundant_match.rb
Overview
Identifies the use of `Regexp#match` or `String#match`, which returns `#<MatchData>`/`nil`. The return value of `=~` is an integral index/`nil` and is more performant.
Constant Summary collapse
- MSG =
'Use `=~` in places where the `MatchData` returned by ' \ '`#match` will not be used.'
- RESTRICT_ON_SEND =
%i[match].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/rubocop/cop/performance/redundant_match.rb', line 38 def on_send(node) return unless match_call?(node) && (!node.value_used? || only_truthiness_matters?(node)) && !(node.parent && node.parent.block_type?) add_offense(node) do |corrector| autocorrect(corrector, node) end end |