Hash#{select,select!} support return Enumerator

if non block given
This commit is contained in:
ksss
2014-03-23 00:38:35 +09:00
parent ff6666632f
commit 5e4626c9ba
+4
View File
@@ -162,6 +162,8 @@ class Hash
# 1.9 Hash#select! returns Hash; ISO says nothing.
def select!(&b)
return to_enum :select! unless block_given?
keys = []
self.each_key{|k|
v = self[k]
@@ -178,6 +180,8 @@ class Hash
# 1.9 Hash#select returns Hash; ISO says nothing.
def select(&b)
return to_enum :select unless block_given?
h = {}
self.each_key{|k|
v = self[k]