Hashes

  • Figure out how to practice your coding in ruby playground.rb
  • Figure out how to use Repl.it to practice your coding skills as well.
  • Practice, Practice and Practice some more!

“Hashing Around”

Start by creating a hash.

Photo by Nicole Wolf on Unsplash
{}hash_name = {'name' => 'Logan', 'favorite color' => 'Yellow'}
hash_name["name"]

Creating a |key, value| pair

Photo by Silas Köhler on Unsplash
new_hash = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}

To get the value for key e above you can do this:

new_hash[:e]
new_hash[:b] = 9new_hash[:name] = "Professor X "
new_hash.keys
new_hash.values
Photo by Ricardo Gomez Angel on Unsplash

Iterating Through A Hash

Iterate through a hash

  • use .each method
  • print out the value
  • use .each method
  • print out both key and value

Learn how to find the methods

rubyonrails.org is a great way to look up methods to use. One method is the select method. This example method displays items only if value of the item is even

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store