FixNum#times is correct?

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

aXJiPiA1LnRpbWVzIHt8aXwgcHV0cyBpfQowCjEKMgozCjQKNQoKCklzIGl0IHRoZSBleHBlY3Rl
ZCBvdXRwdXQ/IEkgd2FzIGV4cGVjdGluZzoKMAoxCjIKMwo0CgoKCi0tIApJw7Fha2kgQmF6IENh
c3RpbGxvCg==
 
B

Ben Bleything

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
=3D> 5

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

5.times {|i| puts "-- #{i}" }

Ben
 
S

Stefano Crocco

Alle Wednesday 11 February 2009, I=F1aki Baz Castillo ha scritto:
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

The 5 you see is the return value of 5.times, which irb displays as it does=
=20
with the value returned by each expression you evaluate. If you try the abo=
ve=20
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
 
A

Alexander Simonov

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

Haha!

ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-darwin9.2.0]
ruby 1.8.6: main0
1
2
3
4
# =3D> 5

11 =D1=84=D0=B5=D0=B2=D1=80. 2009, =D0=B2 10:29, I=C3=B1aki Baz Castillo =
=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB(=D0=B0):
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



--=20
I=C3=B1aki Baz Castillo

- --
WBR, Alexander Simonov (DEVL-RIPE)
Developer, System Administrator
Web Site: http://simonov.in.ua
E-Mail: (e-mail address removed)




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

iEYEARECAAYFAkmSjdgACgkQkr9AYoS+FlX4eQCg6ZuRPBmcH+MxxqiM3T1yMdP7
L5EAnihKNvxYEURo4oTGK8T1UxKejttR
=3DEoOm
-----END PGP SIGNATURE-----
 
I

Iñaki Baz Castillo

El Mi=E9rcoles, 11 de Febrero de 2009, Ben Bleything escribi=F3:
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
=3D> 5

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 :)

Thanks for the explanation.

=2D-=20
I=F1aki Baz Castillo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,966
Members
47,513
Latest member
JeremyLabo

Latest Threads

Top