I find it surprising that Ruby symbols can be typecasted to integers without errors.
So :a.to_i is legal. I was wondering what is the significance of this integer, is it a unique value specific to that symbol?
I find it surprising that Ruby symbols can be typecasted to integers without errors.
Share
You shouldn’t do this, as
Symbol#to_iwas removed in Ruby 1.9 and is thus not compatible going forward. Regardless, the docs say this about it:It is roughly equivalent to calling
object_idon the symbol, as they both end up calling the C functionSYM2ID().