RFS: Hashes - 006

Hashes are key, value data structure, they allow you to store information with some kind of a key and some kind of a value.

Hash Examples

person = {name: "Zack", age: 34}

In this example the hash has a key of name and age, and the values are 'Zack', and 34 respectively. The value can be any kind of data type inside of ruby. We can put hashes inside of an array.

person_2 = {name: "Phavit", age: 1}people = [person, person_2]

We can access the value of the hash by

person[:name]=> "Zack"

In this case the :name is a Symbol.

Let's loop out the name of the people

people.each do |per|  puts per[:name]end

This will loop out the name of the person. Try out some examples from the documentation!