L-exp Mobile

Ruby Symbols in 1.9—End of an Era (and a good thing, too)

:rip.to_i

Ruby symbols have always been immediate objects. That means that, inside the interpreter, they were represented as small integers which references the corresponding symbol text in a lookup table. This made them fast, but it also left code open to denial of service attacks (particular in the context of web applications)—malicious clients could force server code to create arbitrary numbers of symbol table entries, and these were never garbage collected.

Some recent changes in Ruby 1.9 point to the transition away from symbols being immediate objects. In particular, they lose their
integer representation, and hence the methods Fixnum.id2name, Fixnum.to_sym, and Symbol.to_i have been removed. I'm expecting to see symbols migrate to the heap as 1.9 continues to evolve.



Options:   Save This | Share
Viewed 1 times
Published 8 months ago
By Dave Thomas
From Resource PragDave in lists:
Best Ruby on Rails Blogs

Menu

by Genís