13 Iterating over hashes


#1

I can't seem to figure this one out. Can anyone tell me what is wrong with this?

secret_identities = {
"The Batman" => "Bruce Wayne",
"Superman" => "Clark Kent",
"Wonder Woman" => "Diana Prince",
"Freakazoid" => "Dexter Douglas"
}

secret_identities.each do |superhero, alias|
puts "#{superhero}: #{alias}"
end


#2

Your problem probably comes from the keyword alias, which is a keyword reserved by Ruby. Try something else instead.


#3

I don't know if you're still working on this lesson, but I completed it using the below text. I originally had |alter ego, real person| as the placeholder text and was failing. Once I changed to single words, it worked. Which tells me that using multi word placeholders is a no no.

secret_identities = {
"The Batman" => "Bruce Wayne",
"Superman" => "Clark Kent",
"Wonder Woman" => "Diana Prince",
"Freakazoid" => "Dexter Douglas"
}
secret_identities.each do |superhero, real|
puts "#{superhero}: #{real}"
end


#4

Thank you so much! I couldn't figure out what I was doing wrong. :smile:


#5

Thanks for posting this, I used alias as well and it was really confusing me why it wouldn't work!!!