class RuboCop::Cop::Performance::CollectionLiteralInLoop
def optimized_array_include?(node, method, arguments)
See https://github.com/ruby/ruby/pull/12123 for more details.
Since Ruby 3.4, simple arguments to Array#include? are optimized.
def optimized_array_include?(node, method, arguments) return false unless target_ruby_version >= 3.4 && node.array_type? && method == :include? # Disallow include?(1, 2) return false if arguments.count != 1 arg = arguments.first # Allow `include?(foo.bar.baz.bat)` while arg.send_type? return false if arg.arguments.any? # Disallow include?(foo(bar)) break unless arg.receiver arg = arg.receiver end ARRAY_INCLUDE_OPTIMIZED_TYPES.include?(arg.type) end