You have lots of keys => values a hash contains one key (before the arrow) and one value (after the arrow)
You can make an array of hashes. Ruby on rails uses this.
You have to fix the quotes
customer_hash = {
"Ken" => "Fiction",
"William" => "Mystery",
"Catherine" => "Computer",
"Mark" => "Fiction",
"Steve" => "Sports",
"Sam" => "Fiction"
}
But why not do it like this
customer_array_of_hashes = [
{'Ken' => 'Fiction'},
{'William' => 'Mystery'},
{'Catherine' => 'Computer'},
{'Mark' => 'Fiction'},
{'Steve'=> 'Sports'},
{'Sam' => 'Fiction'}
]
Then You can loop trough it like this
customer_array_of_hashes.each do|hash|
hash.each do |key, value|
puts "lastname: " + value + ", firstname: " + key
end
end
You can find alot of all methods on all ruby Classes here
Ruby API
And rails extra methods here
Ruby on rails API
One tip in the end
Try this
irb(main):039:0> customer_array_of_hashes.class
=> Array
If you ever wounder what class you have in ruby the class method will give the answer.
Ok you know that customer_array_of_hashes is an array. One method you can use on arrays is .first
Try this
irb(main):040:0> customer_array_of_hashes.first.class
=> Hash
Ok it is an array of hashes!
Good look!