[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

FixNum#times is correct?

Iñaki Baz Castillo

2/11/2009 8:30:00 AM

aXJiPiA1LnRpbWVzIHt8aXwgcHV0cyBpfQowCjEKMgozCjQKNQoKCklzIGl0IHRoZSBleHBlY3Rl
ZCBvdXRwdXQ/IEkgd2FzIGV4cGVjdGluZzoKMAoxCjIKMwo0CgoKCi0tIApJw7Fha2kgQmF6IENh
c3RpbGxvCg==

4 Answers

Ben Bleything

2/11/2009 8:32:00 AM

0

On Wed, Feb 11, 2009 at 12:29 AM, I=F1aki Baz Castillo <ibc@aliax.net> wrot=
e:
> 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

Stefano Crocco

2/11/2009 8:34:00 AM

0

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

Alexander Simonov

2/11/2009 8:34:00 AM

0

-----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
# =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://sim...
E-Mail: alex@simonov.in.ua




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

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

Iñaki Baz Castillo

2/11/2009 8:40:00 AM

0

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