Ruby's sym.to_i 1

Posted by John Wulff Mon, 21 Jul 2008 18:19:00 GMT

Give this a look:

>> :"5".to_i
=> 148447
>> :"5".to_s.to_i
=> 5
Hurts a little doesn’t it? Here’s the why:
Ruby-Doc.org: sym.to_i returns an integer that is unique for each symbol within a particular execution of a program.

Makes sense, sure. But damn was it painful to figure that one out the hard way.

For more fun with Symbols I suggest What is a ruby symbol? – symbols explained.

Comments

Leave a comment

  1. Avatar
    Zach Hale about 1 hour later:
    That must have been infuriatingly frustrating to debug. I've never done this but now I'll be prepared!
Comments