High-performance Ruby: Faster Symbol.to_s
Join the DZone community and get the full member experience.Join For Free
Here's something that I found useful for shaving a few microseconds off. The performance gain ranges between 10% and 35%! YMMV. Note: updated with suggestion by trans.
class Symbol def to_s @str_rep || (@str_rep = id2name.freeze) end end
Opinions expressed by DZone contributors are their own.