Hashes and Symbols Flashcards
1
Q
What will happen if you try to access a key that doesn’t exist?
A
You will not see an error message, it will print the value of the non-existent key which is ‘nil’
2
Q
If I had the following array of hashes, how would I print out this message on each line? “Toby is a 24 years old male”?
A
my_group = []
person_1 = {name: “Toby”, gender: “male”, age: 24}
person_2 = {name: “Emma”, gender: “female”, age: 45}
my_group «_space;person_1
my_group «_space;person_2
my_group.each { |h| puts “#{h[:name]} is a #{h[:age]} years old #{h[:gender]}”}