Skip to content

Commit aff1db4

Browse files
authored
Merge pull request rails#48412 from andrewn617/fix_defect_in_enumerable_many
Fix defect in Enumerable#many introduced in rails/rails@d862dff
2 parents 349ed43 + 745976b commit aff1db4

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

activesupport/lib/active_support/core_ext/enumerable.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def index_with(default = (no_default = true))
9393
def many?
9494
cnt = 0
9595
if block_given?
96-
any? do |element, *args|
97-
cnt += 1 if yield element, *args
96+
any? do |*args|
97+
cnt += 1 if yield(*args)
9898
cnt > 1
9999
end
100100
else

activesupport/test/core_ext/enumerable_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def test_many
278278
assert_equal false, GenericEnumerable.new([ 1, 2 ]).many? { |x| x > 1 }
279279
assert_equal true, GenericEnumerable.new([ 1, 2, 2 ]).many? { |x| x > 1 }
280280
assert_equal true, GenericEnumerable.new([ 1, 2, 3]).each_with_index.many? { |x, i| x == i + 1 }
281+
assert_equal true, GenericEnumerable.new([ [1, 2], [3, 4] ]).many? { |x| x.sum > 1 }
281282
end
282283

283284
def test_many_iterates_only_on_what_is_needed

0 commit comments

Comments
 (0)