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.

Instructions

1.

Access the key-value pair you added to pets, just like step 2 in the example above.

Use puts to print that value to the console.

Folder Icon

Take this course for free

Already have an account?