summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDaniel Bovensiepen <[email protected]>2012-05-03 16:43:44 +0800
committerDaniel Bovensiepen <[email protected]>2012-05-03 16:43:44 +0800
commitbe20e99938c15ed6ea6dddee44aad5188965a1a0 (patch)
treebb1a8a3e1c48071ffcb99f193fc1550396762079
parent1032e9eecc579cf3462b94ded98b40cdcb385a59 (diff)
downloadmruby-be20e99938c15ed6ea6dddee44aad5188965a1a0.tar.gz
mruby-be20e99938c15ed6ea6dddee44aad5188965a1a0.zip
Add documentation to String
-rw-r--r--mrblib/string.rb64
1 files changed, 55 insertions, 9 deletions
diff --git a/mrblib/string.rb b/mrblib/string.rb
index 78f2bea9d..ad7e1fca1 100644
--- a/mrblib/string.rb
+++ b/mrblib/string.rb
@@ -1,8 +1,14 @@
+##
+# String
#
-# String
-#
+# ISO 15.2.10
class String
- # 15.2.10.5.15
+
+ ##
+ # Calls the given block for each line
+ # and pass the respective line.
+ #
+ # ISO 15.2.10.5.15
def each_line(&block)
# expect that str.index accepts an Integer for 1st argument as a byte data
offset = 0
@@ -14,7 +20,13 @@ class String
self
end
- # 15.2.10.5.18
+ ##
+ # Replace all matches of +pattern+ with +replacement+.
+ # Call block (if given) for each match and replace
+ # +pattern+ with the value of the block. Return the
+ # final value.
+ #
+ # ISO 15.2.10.5.18
def gsub(*args, &block)
unless (args.size == 1 && block) || args.size == 2
raise ArgumentError, "wrong number of arguments"
@@ -23,7 +35,13 @@ class String
### *** TODO *** ###
end
- # 15.2.10.5.19
+ ##
+ # Replace all matches of +pattern+ with +replacement+.
+ # Call block (if given) for each match and replace
+ # +pattern+ with the value of the block. Modify
+ # +self+ with the final value.
+ #
+ # ISO 15.2.10.5.19
def gsub!(*args, &block)
str = self.gsub(*args, &block)
if str != self
@@ -34,12 +52,23 @@ class String
end
end
- # 15.2.10.5.32
+ ##
+ # Calls the given block for each match of +pattern+
+ # If no block is given return an array with all
+ # matches of +pattern+.
+ #
+ # ISO 15.2.10.5.32
def scan(reg, &block)
### *** TODO *** ###
end
- # 15.2.10.5.36
+ ##
+ # Replace only the first match of +pattern+ with
+ # +replacement+. Call block (if given) for each
+ # match and replace +pattern+ with the value of the
+ # block. Return the final value.
+ #
+ # ISO 15.2.10.5.36
def sub(*args, &block)
unless (args.size == 1 && block) || args.size == 2
raise ArgumentError, "wrong number of arguments"
@@ -48,7 +77,13 @@ class String
### *** TODO *** ###
end
- # 15.2.10.5.37
+ ##
+ # Replace only the first match of +pattern+ with
+ # +replacement+. Call block (if given) for each
+ # match and replace +pattern+ with the value of the
+ # block. Modify +self+ with the final value.
+ #
+ # ISO 15.2.10.5.37
def sub!(*args, &block)
str = self.sub(*args, &block)
if str != self
@@ -59,6 +94,9 @@ class String
end
end
+ ##
+ # Call the given block for each character of
+ # +self+.
def each_char(&block)
pos = 0
while(pos < self.size)
@@ -68,6 +106,8 @@ class String
self
end
+ ##
+ # Call the given block for each byte of +self+.
def each_byte(&block)
bytes = self.unpack("C*")
pos = 0
@@ -78,6 +118,9 @@ class String
self
end
+ ##
+ # Modify +self+ by replacing the content of +self+
+ # at the position +pos+ with +value+.
def []=(pos, value)
b = self[0, pos]
a = self[pos+1..-1]
@@ -86,7 +129,10 @@ class String
end
end
-# include modules
+##
+# String is comparable
+#
+# ISO 15.2.10.3
module Comparable; end
class String
include Comparable