Skip to content

Commit d862dff

Browse files
committed
Fix Enumerable#many? to handle previous enumerator methods parameters
1 parent 586436d commit d862dff

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
@@ -144,8 +144,8 @@ def index_with(default = (no_default = true))
144144
def many?
145145
cnt = 0
146146
if block_given?
147-
any? do |element|
148-
cnt += 1 if yield element
147+
any? do |element, *args|
148+
cnt += 1 if yield element, *args
149149
cnt > 1
150150
end
151151
else

activesupport/test/core_ext/enumerable_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ def test_many
255255
assert_equal false, GenericEnumerable.new([ 2 ]).many? { |x| x > 1 }
256256
assert_equal false, GenericEnumerable.new([ 1, 2 ]).many? { |x| x > 1 }
257257
assert_equal true, GenericEnumerable.new([ 1, 2, 2 ]).many? { |x| x > 1 }
258+
assert_equal true, GenericEnumerable.new([ 1, 2, 3]).each_with_index.many? { |x, i| x == i + 1 }
258259
end
259260

260261
def test_many_iterates_only_on_what_is_needed

0 commit comments

Comments
 (0)