[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 ?

Paolo Negri

9/30/2006 12:03:00 AM

because the second version converts the given string in base 2.

to_i accept an optional parameter which is the base of the integer (by
default 10)
http://www.ruby-doc.org/core/classes/String.ht...


'1'.to_i*2 calls the method * applied to the value returned by to_i
'1'.to_i *2 is like '1'.to_i(*2)
anyway a more common way to write the expression is

'1'.to_i * 2

Paolo

On 30/09/06, Giovanni Intini <intinig@gmail.com> 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
>
>