Learn

What we just showed you was hash literal notation. We call it that because you literally describe what you want in the hash: you give it a name and you set it equal to one or more key => value pairs inside curly braces.

You can also create a hash using Hash.new, like so:

my_hash = Hash.new

Setting a variable equal to Hash.new creates a new, empty hash; it’s the same as setting the variable equal to empty curly braces ({}).

Instructions

1.

Use Hash.new to create a new hash called pets. Hash must be capitalized, or Ruby won’t know what you’re talking about!

Take this course for free

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?