Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix defect in Enumerable#many introduced in rails/rails@d862dff #48412

Merged
merged 1 commit into from Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions activesupport/lib/active_support/core_ext/enumerable.rb
Expand Up @@ -93,8 +93,8 @@ def index_with(default = (no_default = true))
def many?
cnt = 0
if block_given?
any? do |element, *args|
cnt += 1 if yield element, *args
any? do |*args|
cnt += 1 if yield(*args)
cnt > 1
end
else
Expand Down
1 change: 1 addition & 0 deletions activesupport/test/core_ext/enumerable_test.rb
Expand Up @@ -278,6 +278,7 @@ def test_many
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 }
assert_equal true, GenericEnumerable.new([ [1, 2], [3, 4] ]).many? { |x| x.sum > 1 }
end

def test_many_iterates_only_on_what_is_needed
Expand Down