downto(p1)
public
Iterates the given block, passing decreasing values from int down
to and including limit.
If no block is given, an Enumerator is
returned instead.
5.downto(1) { |n| print n, ".. " }
print " Liftoff!\n"
Show source
static VALUE
int_downto(VALUE from, VALUE to)
{
RETURN_SIZED_ENUMERATOR(from, 1, &to, int_downto_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));
}
if (NIL_P(c)) rb_cmperr(i, to);
}
return from;
}