Permalink
Browse files

ActiveSupport::HashWithIndifferentAccess select and reject should ret…

…urn enumerator if called without block
  • Loading branch information...
imanel authored and sgrif committed May 12, 2015
1 parent 89448a7 commit 800d5ae36c8a906e6fb26d4064a6a75236f84186
@@ -1,3 +1,10 @@
* ActiveSupport::HashWithIndifferentAccess `select` and `reject` will now return
enumerator if called without block.
Fixes #20095
*Bernard Potocki*
* Removed `ActiveSupport::Concurrency::Latch`, superseded by `Concurrent::CountDownLatch`
from the concurrent-ruby gem.
@@ -238,10 +238,12 @@ def deep_symbolize_keys; to_hash.deep_symbolize_keys! end
def to_options!; self end
def select(*args, &block)
return to_enum(:select) unless block_given?
dup.tap { |hash| hash.select!(*args, &block) }
end
def reject(*args, &block)
return to_enum(:reject) unless block_given?
dup.tap { |hash| hash.reject!(*args, &block) }
end
@@ -551,6 +551,11 @@ def test_indifferent_select
assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash
end
def test_indifferent_select_returns_enumerator
enum = ActiveSupport::HashWithIndifferentAccess.new(@strings).select
assert_instance_of Enumerator, enum
end
def test_indifferent_select_returns_a_hash_when_unchanged
hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).select {|k,v| true}
@@ -572,6 +577,11 @@ def test_indifferent_reject
assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash
end
def test_indifferent_reject_returns_enumerator
enum = ActiveSupport::HashWithIndifferentAccess.new(@strings).reject
assert_instance_of Enumerator, enum
end
def test_indifferent_reject_bang
indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@strings)
indifferent_strings.reject! {|k,v| v != 1}

0 comments on commit 800d5ae

Please sign in to comment.