If something doesn't exist in value, you will receive (nil).
If you don't want that you can create a default value. Using hash.new you can specify what it should be.
Symbols:
There can only be one copy of a symbol at a time
Symbols make good hash keys for a few reasons:
-They’re immutable, meaning they can’t be changed once they’re created;
-Only one copy of any symbol exists at a given time, so they save memory;
-Symbol-as-keys are faster than strings-as-keys
because of the above two reasons.
Converting Between Symbols and Strings
You can use (.intern) to switch a string into a symbol
(=>) hash rocket style
Alternate way than hash rocket for symbols
When you want to filter a hash for values that meet a certain criteria
Top comments (0)