upto(...)
public
Iterates through successive values, starting at str and ending at
other_str inclusive, passing each
value in turn to the block. The String#succ
method is used to generate each value. If
optional second argument exclusive is omitted or is false, the last value
will be included; otherwise it will be excluded.
"a8".upto("b6") {|s| print s, ' ' }
for s in "a8".."b6"
print s, ' '
end
produces:
a8 a9 b0 b1 b2 b3 b4 b5 b6
a8 a9 b0 b1 b2 b3 b4 b5 b6
Show source
/*
* call-seq:
* 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. 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"
* print s, ' '
* end
*
* <em>produces:</em>
*
* a8 a9 b0 b1 b2 b3 b4 b5 b6
* a8 a9 b0 b1 b2 b3 b4 b5 b6
*/
static VALUE
rb_str_upto_m(argc, argv, beg)
int argc;
VALUE *argv;
VALUE beg;
{
VALUE end, exclusive;
rb_scan_args(argc, argv, "11", &end, &exclusive);
return rb_str_upto(beg, end, RTEST(exclusive));
}