diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-05-07 22:50:24 -0700 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-05-07 22:50:24 -0700 |
| commit | c80103e89a7ddcbaa7b5fc470358a4bcae327953 (patch) | |
| tree | 4ebbc46f688f1d4c4e81eec715a9314ebb286c73 /mrblib | |
| parent | 11e70f2191caecfe546f8a97baf284c1cfc25e00 (diff) | |
| parent | c9edc5b02ee07aa2b8caa994910d31273260ca22 (diff) | |
| download | mruby-c80103e89a7ddcbaa7b5fc470358a4bcae327953.tar.gz mruby-c80103e89a7ddcbaa7b5fc470358a4bcae327953.zip | |
Merge pull request #1237 from monaka/pr-cleanup-hash
Cleanup hash
Diffstat (limited to 'mrblib')
| -rw-r--r-- | mrblib/hash.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/mrblib/hash.rb b/mrblib/hash.rb index c304d4845..f7cdbdc6d 100644 --- a/mrblib/hash.rb +++ b/mrblib/hash.rb @@ -24,6 +24,23 @@ class Hash # Calls the given block for each element of +self+ # and pass the key and value of each element. # + # call-seq: + # hsh.each {| key, value | block } -> hsh + # hsh.each_pair {| key, value | block } -> hsh + # hsh.each -> an_enumerator + # hsh.each_pair -> an_enumerator + # + # + # If no block is given, an enumerator is returned instead. + # + # h = { "a" => 100, "b" => 200 } + # h.each {|key, value| puts "#{key} is #{value}" } + # + # <em>produces:</em> + # + # a is 100 + # b is 200 + # # ISO 15.2.13.4.9 def each(&block) self.keys.each{|k| block.call([k, self[k]])} @@ -34,6 +51,20 @@ class Hash # Calls the given block for each element of +self+ # and pass the key of each element. # + # call-seq: + # hsh.each_key {| key | block } -> hsh + # hsh.each_key -> an_enumerator + # + # If no block is given, an enumerator is returned instead. + # + # h = { "a" => 100, "b" => 200 } + # h.each_key {|key| puts key } + # + # <em>produces:</em> + # + # a + # b + # # ISO 15.2.13.4.10 def each_key(&block) self.keys.each{|k| block.call(k)} @@ -44,6 +75,20 @@ class Hash # Calls the given block for each element of +self+ # and pass the value of each element. # + # call-seq: + # hsh.each_value {| value | block } -> hsh + # hsh.each_value -> an_enumerator + # + # If no block is given, an enumerator is returned instead. + # + # h = { "a" => 100, "b" => 200 } + # h.each_value {|value| puts value } + # + # <em>produces:</em> + # + # 100 + # 200 + # # ISO 15.2.13.4.11 def each_value(&block) self.keys.each{|k| block.call(self[k])} |
