Fix `Enumerable#many?` to handle previous enumerator methods parameters

This commit is contained in:
fatkodima 2022-11-08 20:53:40 +02:00
parent 586436d370
commit d862dffadd
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