summaryrefslogtreecommitdiffhomepage
path: root/mrblib/hash.rb
diff options
context:
space:
mode:
authorDaniel Bovensiepen <[email protected]>2012-05-06 18:15:23 +0800
committerDaniel Bovensiepen <[email protected]>2012-05-06 18:15:23 +0800
commit8f4c1af9e4ca995d891c1f1b52113e90fe213ba5 (patch)
tree15c7858826f1452c37a285143ec2a21ae78aa27e /mrblib/hash.rb
parentb584bb715b3f68a4b356fcce549e5f29342e6ff0 (diff)
downloadmruby-8f4c1af9e4ca995d891c1f1b52113e90fe213ba5.tar.gz
mruby-8f4c1af9e4ca995d891c1f1b52113e90fe213ba5.zip
Add documentation to Hash
Diffstat (limited to 'mrblib/hash.rb')
-rw-r--r--mrblib/hash.rb52
1 files changed, 44 insertions, 8 deletions
diff --git a/mrblib/hash.rb b/mrblib/hash.rb
index 7157684f8..b32c30b83 100644
--- a/mrblib/hash.rb
+++ b/mrblib/hash.rb
@@ -1,8 +1,17 @@
+##
+# Hash
#
-# Hash
-#
+# ISO 15.2.13
class Hash
- # 15.2.13.4.8
+
+ ##
+ # Delete the element with the key +key+.
+ # Return the value of the element if +key+
+ # was found. Return nil if nothing was
+ # found. If a block is given, call the
+ # block with the value of the element.
+ #
+ # ISO 15.2.13.4.8
def delete(key, &block)
if block && ! self.has_key?(key)
block.call(key)
@@ -11,29 +20,53 @@ class Hash
end
end
- # 15.2.13.4.9
+ ##
+ # Calls the given block for each element of +self+
+ # and pass the key and value of each element.
+ #
+ # ISO 15.2.13.4.9
def each(&block)
self.keys.each{|k| block.call([k, self[k]])}
self
end
- # 15.2.13.4.10
+ ##
+ # Calls the given block for each element of +self+
+ # and pass the key of each element.
+ #
+ # ISO 15.2.13.4.10
def each_key(&block)
self.keys.each{|k| block.call(k)}
self
end
- # 15.2.13.4.11
+ ##
+ # Calls the given block for each element of +self+
+ # and pass the value of each element.
+ #
+ # ISO 15.2.13.4.11
def each_value(&block)
self.keys.each{|k| block.call(self[k])}
self
end
- # 15.2.13.4.16
+ ##
+ # Create a direct instance of the class Hash.
+ #
+ # ISO 15.2.13.4.16
def initialize(*args, &block)
self.__init_core(block, *args)
end
+ ##
+ # Return a hash which contains the content of
+ # +self+ and +other+. If a block is given
+ # call the block for each duplicate key and
+ # pass the key, old value and new value.
+ # The value of the block will be replacing
+ # the duplicate element in the has which will
+ # be returned.
+ #
# 15.2.13.4.22
def merge(other, &block)
h = {}
@@ -51,7 +84,10 @@ class Hash
end
end
-# include modules
+##
+# Hash is enumerable
+#
+# ISO 15.2.13.3
module Enumerable; end
class Hash
include Enumerable