summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-28 08:52:57 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-28 08:52:57 +0000
commitacdda413ab35c13e85bd3cfe2ed45aacbb059932 (patch)
tree8d90a1c939819ebb18abd1c725c01457d4d18df7 /string.c
parentd55bb05153a2fbc8b9b74636cd47351a3d51a4d7 (diff)
Merge from ruby_1_8.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@16671 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/string.c b/string.c
index c23f650496..7e26edb5b2 100644
--- a/string.c
+++ b/string.c
@@ -1492,12 +1492,13 @@ rb_str_upto(beg, end, excl)
/*
* call-seq:
- * str.upto(other_str) {|s| block } => str
+ * str.upto(other_str, exclusive=false) {|s| block } => str
*
* Iterates through successive values, starting at <i>str</i> and
* ending at <i>other_str</i> inclusive, passing each value in turn to
* the block. The <code>String#succ</code> method is used to generate
- * each value.
+ * each value. If optional second argument exclusive is omitted or is <code>false</code>,
+ * the last value will be included; otherwise it will be excluded.
*
* "a8".upto("b6") {|s| print s, ' ' }
* for s in "a8".."b6"
@@ -1511,10 +1512,15 @@ rb_str_upto(beg, end, excl)
*/
static VALUE
-rb_str_upto_m(beg, end)
- VALUE beg, end;
+rb_str_upto_m(argc, argv, beg)
+ int argc;
+ VALUE argv, beg;
{
- return rb_str_upto(beg, end, Qfalse);
+ VALUE end, exclusive;
+
+ rb_scan_args(argc, argv, "11", &end, &exclusive);
+
+ return rb_str_upto(beg, end, RTEST(exclusive));
}
static VALUE
@@ -4929,7 +4935,7 @@ Init_String()
rb_define_method(rb_cString, "succ!", rb_str_succ_bang, 0);
rb_define_method(rb_cString, "next", rb_str_succ, 0);
rb_define_method(rb_cString, "next!", rb_str_succ_bang, 0);
- rb_define_method(rb_cString, "upto", rb_str_upto_m, 1);
+ rb_define_method(rb_cString, "upto", rb_str_upto_m, -1);
rb_define_method(rb_cString, "index", rb_str_index_m, -1);
rb_define_method(rb_cString, "rindex", rb_str_rindex_m, -1);
rb_define_method(rb_cString, "replace", rb_str_replace, 1);