Merge pull request #1923 from ksss/hash-enumerator-select

Hash#{select,select!} support return Enumerator
This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-03-23 16:36:19 +09:00
2 changed files with 20 additions and 2 deletions
@@ -494,6 +494,20 @@ assert 'Hash#each_value' do
assert_equal [1,2], {a:1,b:2}.each_value.to_a.sort
end
assert 'Hash#select' do
h = {1=>2,3=>4,5=>6}
hret = h.select.with_index {|a,b| a[1] == 4}
assert_equal({3=>4}, hret)
assert_equal({1=>2,3=>4,5=>6}, h)
end
assert 'Hash#select!' do
h = {1=>2,3=>4,5=>6}
hret = h.select!.with_index {|a,b| a[1] == 4}
assert_equal h, hret
assert_equal({3=>4}, h)
end
assert 'Range#each' do
a = (1..5)
b = a.each