Second some You should do this yes .
Symbols are stored internally in a table as unsigned integers, which saves a lot of memory compared to using strings. As a result, the comparison between symbols is much faster.
Another advantage is that symbols are immutable, whereas strings can have the content changed and somehow "break" the hash .
But there are always side effects.
One of them is that the symbols are not collected and will reside "eternally" in the interpreter table.
The impact will be small if you use only explicit symbols in the code. However, if you use the to_sym
function to get the symbols corresponding to many different strings, especially if these strings have external source , the use of permanently allocated memory can increase considerably.
Specifically speaking about the example of the question, the hash = {:indice => 'valor'}
and hash = {indice: 'valor'}
excerpts are equivalent, the former being used in Ruby until version 1.8 and the second was introduced in ruby 1.9.