summaryrefslogtreecommitdiffhomepage
path: root/mrblib
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-03-23 02:11:54 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-03-23 02:11:54 +0900
commit76b2ba886a1472932f37dbe5759725d23be88301 (patch)
tree82d268971149b34f6a7d34f2cfb170f89247f055 /mrblib
parent539d9cb855e396047cccccc84ffc88825d77bdf7 (diff)
parent5386cd9b9b8770ddb3683687fd1ad0e5bbccae4b (diff)
downloadmruby-76b2ba886a1472932f37dbe5759725d23be88301.tar.gz
mruby-76b2ba886a1472932f37dbe5759725d23be88301.zip
Merge pull request #1916 from ksss/hash-enumerator
Hash#each_{key,value} support return Enumerator if non block given
Diffstat (limited to 'mrblib')
-rw-r--r--mrblib/hash.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/mrblib/hash.rb b/mrblib/hash.rb
index 0423f7edc..cd6ba8935 100644
--- a/mrblib/hash.rb
+++ b/mrblib/hash.rb
@@ -69,6 +69,8 @@ class Hash
#
# ISO 15.2.13.4.10
def each_key(&block)
+ return to_enum :each_key unless block_given?
+
self.keys.each{|k| block.call(k)}
self
end
@@ -93,6 +95,8 @@ class Hash
#
# ISO 15.2.13.4.11
def each_value(&block)
+ return to_enum :each_value unless block_given?
+
self.keys.each{|k| block.call(self[k])}
self
end