Skip to content

Commit 4129196

Browse files
committed
Merge pull request rails#20125
Manually merged to fix conflicts.
2 parents 89448a7 + 800d5ae commit 4129196

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

activesupport/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
* ActiveSupport::HashWithIndifferentAccess `select` and `reject` will now return
2+
enumerator if called without block.
3+
4+
Fixes #20095
5+
6+
*Bernard Potocki*
7+
18
* Removed `ActiveSupport::Concurrency::Latch`, superseded by `Concurrent::CountDownLatch`
29
from the concurrent-ruby gem.
310

activesupport/lib/active_support/hash_with_indifferent_access.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,12 @@ def deep_symbolize_keys; to_hash.deep_symbolize_keys! end
238238
def to_options!; self end
239239

240240
def select(*args, &block)
241+
return to_enum(:select) unless block_given?
241242
dup.tap { |hash| hash.select!(*args, &block) }
242243
end
243244

244245
def reject(*args, &block)
246+
return to_enum(:reject) unless block_given?
245247
dup.tap { |hash| hash.reject!(*args, &block) }
246248
end
247249

activesupport/test/core_ext/hash_ext_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,11 @@ def test_indifferent_select
551551
assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash
552552
end
553553

554+
def test_indifferent_select_returns_enumerator
555+
enum = ActiveSupport::HashWithIndifferentAccess.new(@strings).select
556+
assert_instance_of Enumerator, enum
557+
end
558+
554559
def test_indifferent_select_returns_a_hash_when_unchanged
555560
hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).select {|k,v| true}
556561

@@ -572,6 +577,11 @@ def test_indifferent_reject
572577
assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash
573578
end
574579

580+
def test_indifferent_reject_returns_enumerator
581+
enum = ActiveSupport::HashWithIndifferentAccess.new(@strings).reject
582+
assert_instance_of Enumerator, enum
583+
end
584+
575585
def test_indifferent_reject_bang
576586
indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@strings)
577587
indifferent_strings.reject! {|k,v| v != 1}

0 commit comments

Comments
 (0)