[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: "1".to_i *2 == 1 && "1".to_i*2 == 2 ?

Justin Collins

9/29/2006 11:57:00 PM

Giovanni Intini wrote:
> Can anyone explain to me why
>
> "1".to_i*2 is equal to 2
> and
> "1".to_i *2 is equale to 1?
>
> Thanks
> Giovanni
>


It seems to be interpreting

"1".to_i *2

as

"1".to_i(*2)

or

"1".to_i(2)

which is 1. Remember the * in function calls is the unarray operator. Kinda weird in this case, though.


-Justin
1 Answer

David Vallner

9/30/2006 5:04:00 PM

0

Collins, Justin wrote:
> Remember the * in function calls is the unarray operator. Kinda weird in this case, though.
>

Reminds me that for Ruby 2, the splat operator was supposed to be a
little more predictable. Anything of that in Ruby 1.9? Can't recall
anything on the change sumamry page about that. This sounds like a
rather nasty gotcha to the people that are lazy about the
one-space-around-operators style convention.

David Vallner