not equal? "5".to_i+ "6".to_i and "5".to_i +"6".to_i

R

Rimantas Liubertas

"5".to_i+ "6".to_i
=> 11
=> 5

The second case +"6".to_i is treated as an argument for to_i method.
This will make it more obvious:=> 7

"111".to_i +"2".to_i is equivalent to "111".to_i(2), hence the result.


Regards,
Rimantas
 
E

Eric Jacoboni

cap said:
ruby 1.8.5 (2006-12-25 patchlevel 12) [i686-linux]

=> 11

so, you're calling "5".to_i.+("6".to_i), ie. "5".to_i.+(6),
ie. 5.+(6), ie. 11

you're calling "5".to_i(+"6".to_i), ie. "5".to_i(6),
ie. "5" converted in base 6, ie 5

Rule of thumb : always put spaces around operators...

--
 
E

Eric Jacoboni

you're calling "5".to_i(+"6".to_i), ie. "5".to_i(6),
ie. "5" converted in base 6, ie 5

Ooops... i wanted to say "5" in base 6, converted to int...

--
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top