Learn

Symbols pop up in a lot of places in Ruby, but they’re primarily used either as hash keys or for referencing method names. (We’ll see how symbols can reference methods in a later lesson.)

sounds = { :cat => "meow", :dog => "woof", :computer => 10010110, }

Symbols make good hash keys for a few reasons:

  1. They’re immutable, meaning they can’t be changed once they’re created;
  2. Only one copy of any symbol exists at a given time, so they save memory;
  3. Symbol-as-keys are faster than strings-as-keys because of the above two reasons.

Instructions

1.

Add at least two more keys to the symbol_hash hash replacing the ______ blanks.

The keys should all be symbols; their associated values can be anything you like.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?