Merge pull request #46448 from fatkodima/fix-many-additional-arguments

This commit is contained in:
Jean Boussier 2022-11-09 01:26:14 +01:00 committed by GitHub
commit e5f3d69203
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -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

View File

@ -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