-
-
Notifications
You must be signed in to change notification settings - Fork 86
Open
Description
Steps to reproduce the problem
items = %w[A B]
one = items.map { it.match(/A/)&.to_s }
# Use `String#include?` instead of a regex match with literal-only pattern. [[Correctable] Performance/StringInclude]
two = items.map { it.include?('A') } # "Whatever you say" -- Bugs Bunny
# Much, much later ...
pp [one, two] # [["A", nil], [true, false]]
Expected behavior
We're assigning the result to a variable in order to do unmentionable stuff with the match later if it was found.
Actual behavior
Cop doesn't see the broader picture and writes us a ticket thinking we just want to test for existence.
RuboCop version
ruby 2025-08-01 30a20bc16
rubocop 2025-10-04 a08091813
System Version: macOS 15.6 (24G84)
Model Identifier: MacBookAir10,1
Metadata
Metadata
Assignees
Labels
No labels