Alle gioved=EC 13 dicembre 2007, John Maclean ha scritto:
> Why does the output stop at eight. Shouldn't the class of nine be
> shown also?
>
> 9.times {|x| print x , " ", x.class, "\n" }
> 0 Fixnum
> 1 Fixnum
> 2 Fixnum
> 3 Fixnum
> 4 Fixnum
> 5 Fixnum
> 6 Fixnum
> 7 Fixnum
> 8 Fixnum
> =3D> 9

No. From the ri documentation of Integer#times:

 int.times {|i| block }     =3D> int
=2D-----------------------------------------------------------------------
 Iterates block int times, passing in values from zero to int - 1.

This means that, in your case, it should call the blocks 9 times, from 0 to=
 8.=20
If it also passed 9 to the block, it would make 10 iterations, not 9.

If you want to include both 0 and 9, you can use upto instead of times:

0.upto(9){|x| puts "#{x} #{x.class}"}

I hope this helps

Stefano