Code Editor
Learn
Hashes and Symbols

The Story So Far

Recall that hashes are collections of key-value pairs, where a unique key is associated with some value. For example:

breakfast = { "bacon" => "tasty", "eggs" => "tasty", "oatmeal" => "healthy", "OJ" => "juicy" }

Remember that keys must be unique, but values can repeat. That's why we can have more than one key share the value "tasty.")

We can create hashes several ways, but two of the most popular are

  1. hash literal notation:
new_hash = { "one" => 1 }

and

2. hash constructor notation:

new_hash = Hash.new
Report a Bug
If you see a bug or any other issue with this page, please report it here.