End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Integer#upto
int.upto(limit) {|i| block } → self
int.upto(limit) → an_enumerator
numeric.c
View on GitHub ↗
static VALUE
int_upto(VALUE from, VALUE to)
{
RETURN_SIZED_ENUMERATOR(from, 1, &to, int_upto_size);
if (FIXNUM_P(from) && FIXNUM_P(to)) {
long i, end;
end = FIX2LONG(to);
for (i = FIX2LONG(from); i <= end; i++) {
rb_yield(LONG2FIX(i));
}
}
else {
VALUE i = from, c;
while (!(c = rb_funcall(i, '>', 1, to))) {
rb_yield(i);
i = rb_funcall(i, '+', 1, INT2FIX(1));
}
ensure_cmp(c, i, to);
}
return from;
}
Iterates the given block, passing in integer values from int up to and including limit.
If no block is given, an Enumerator is returned instead.
Example
5.upto(10) {|i| print i, " " } #=> 5 6 7 8 9 10