FixNum#times is correct?

irb> 5.times {|i| puts i}
0
1
2
3
4
5

Is it the expected output? I was expecting:
0
1
2
3
4

On Wed, Feb 11, 2009 at 12:29 AM, Iñaki Baz C. [email protected] wrote:

irb> 5.times {|i| puts i}
0
1
2
3
4
5

I think you may have clipped some of the output. Here’s what I get:

irb(main):005:0> 5.times {|i| puts i}
0
1
2
3
4
=> 5

It’s puts’ing 0-4, and then returning 5. To see this more clearly, try
this:

5.times {|i| puts “-- #{i}” }

Ben

Alle Wednesday 11 February 2009, Iñaki Baz C. ha scritto:

0
1
2
3
4

The 5 you see is the return value of 5.times, which irb displays as it
does
with the value returned by each expression you evaluate. If you try the
above
code from a script or from command line, you’ll get the expected result:

ruby -e ‘5.times{|i| puts i}’

0
1
2
3
4

Stefano

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Haha!

ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-darwin9.2.0]
ruby 1.8.6: main

5.times {|i| puts i }
0
1
2
3
4

=> 5

11 февр. 2009, в 10:29, Iñaki Baz C. написал(а):

0
1
2
3
4


Iñaki Baz C.


WBR, Alexander Simonov (DEVL-RIPE)
Developer, System A.
Web S.: http://simonov.in.ua
E-Mail: [email protected]

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (Darwin)

iEYEARECAAYFAkmSjdgACgkQkr9AYoS+FlX4eQCg6ZuRPBmcH+MxxqiM3T1yMdP7
L5EAnihKNvxYEURo4oTGK8T1UxKejttR
=EoOm
-----END PGP SIGNATURE-----

El Miércoles, 11 de Febrero de 2009, Ben B.
escribió:> It’s puts’ing 0-4, and then returning 5. To see this more clearly, try

this:

5.times {|i| puts “-- #{i}” }

Ops, my IRB configuration is not helping me :slight_smile:

Thanks for the explanation.