Click here to navigate the course.

Drag the edges to resize the window.

Code Editor
Learn
Data Structures

Accessing Hash Values

You can access values in a hash just like an array.

pets = { "Stevie" => "cat", "Bowser" => "hamster", "Kevin Sorbo" => "fish" } puts pets["Stevie"] # will print "cat"
  1. In the example above, we create a hash called pets.
  2. Then we print cat by accessing the key "Stevie" in the pets hash.
Report a Bug
If you see a bug or any other issue with this page, please report it here.