summaryrefslogtreecommitdiffhomepage
path: root/mrblib/array.rb
diff options
context:
space:
mode:
authorDaniel Bovensiepen <[email protected]>2012-05-02 21:19:00 +0800
committerDaniel Bovensiepen <[email protected]>2012-05-02 21:19:00 +0800
commit2c48bf4527dfe3aed434fffb8d1a044a420a18b9 (patch)
treeec960647039f83ea38566a0d795efdda9185efa1 /mrblib/array.rb
parent3ea3a081c410d79ed942ec499004685854ae99bb (diff)
downloadmruby-2c48bf4527dfe3aed434fffb8d1a044a420a18b9.tar.gz
mruby-2c48bf4527dfe3aed434fffb8d1a044a420a18b9.zip
Add Documentation for Array
Diffstat (limited to 'mrblib/array.rb')
-rw-r--r--mrblib/array.rb41
1 files changed, 33 insertions, 8 deletions
diff --git a/mrblib/array.rb b/mrblib/array.rb
index a70832399..905b41cb0 100644
--- a/mrblib/array.rb
+++ b/mrblib/array.rb
@@ -1,8 +1,14 @@
+##
+# Array
#
-# Array
-#
+# ISO 15.2.12
class Array
- # 15.2.12.5.10
+
+ ##
+ # Calls the given block for each element of +self+
+ # and pass the respective element.
+ #
+ # ISO 15.2.12.5.10
def each(&block)
idx = 0
while(idx < length)
@@ -12,7 +18,11 @@ class Array
self
end
- # 15.2.12.5.11
+ ##
+ # Calls the given block for each element of +self+
+ # and pass the index of the respective elment.
+ #
+ # ISO 15.2.12.5.11
def each_index(&block)
idx = 0
while(idx < length)
@@ -22,7 +32,12 @@ class Array
self
end
- # 15.2.12.5.7
+ ##
+ # Calls the given block for each element of +self+
+ # and pass the respective element. Each element will
+ # be replaced by the resulting values.
+ #
+ # ISO 15.2.12.5.7
def collect!(&block)
self.each_index{|idx|
self[idx] = block.call(self[idx])
@@ -30,11 +45,16 @@ class Array
self
end
- # 15.2.12.5.20
- # map!(&block)
+ ##
+ # Alias for collect!
+ #
+ # ISO 15.2.12.5.20
alias map! collect!
- # 15.2.12.5.15
+ ##
+ # Private method for Array creation.
+ #
+ # ISO 15.2.12.5.15
def initialize(size=0, obj=nil, &block)
raise TypeError, "expected Integer for 1st argument" unless size.kind_of? Integer
raise ArgumentError, "negative array size" if size < 0
@@ -53,6 +73,8 @@ class Array
self
end
+ ##
+ # Delete element with index +key+
def delete(key, &block)
while i = self.index(key)
self.delete_at(i)
@@ -73,6 +95,9 @@ class Array
include Enumerable
include Comparable
+ ##
+ # Sort all elements and replace +self+ with these
+ # elements.
def sort!(&block)
self.replace(self.sort(&block))
end