Posts tagged ‘memory



Why use symbols as hash keys in Ruby?

Posted on: Wednesday, Mar 12, 2014

Question A lot of times people use symbols as keys in a Ruby hash. What’s the advantage over using a string? E.g.:   hash[:name]  vs.   hash['name'] Answer Using symbols not only saves time when doing comparisons, but also saves memory, because they are only stored once. Symbols in Ruby are basically “immutable strings” .. that means that they can not be […]