From d862dffaddcec57f117add1311b3add8bf3f3f98 Mon Sep 17 00:00:00 2001 From: fatkodima Date: Tue, 8 Nov 2022 20:53:40 +0200 Subject: [PATCH] Fix `Enumerable#many?` to handle previous enumerator methods parameters --- activesupport/lib/active_support/core_ext/enumerable.rb | 4 ++-- activesupport/test/core_ext/enumerable_test.rb | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index fb5a6d48fdf..c996b154b3f 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -144,8 +144,8 @@ module Enumerable def many? cnt = 0 if block_given? - any? do |element| - cnt += 1 if yield element + any? do |element, *args| + cnt += 1 if yield element, *args cnt > 1 end else diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index f0533af3f9e..b1d3dae6334 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -255,6 +255,7 @@ class EnumerableTests < ActiveSupport::TestCase assert_equal false, GenericEnumerable.new([ 2 ]).many? { |x| x > 1 } assert_equal false, GenericEnumerable.new([ 1, 2 ]).many? { |x| x > 1 } assert_equal true, GenericEnumerable.new([ 1, 2, 2 ]).many? { |x| x > 1 } + assert_equal true, GenericEnumerable.new([ 1, 2, 3]).each_with_index.many? { |x, i| x == i + 1 } end def test_many_iterates_only_on_what_is_needed