13. Iterating Over Hashes


#1



13. Iterating Over Hashes


While performing this exercise, I first attempted to use "alias" as 'x' and "name" as 'y' but after running the code it didn't work. When I replaced these with just 'x' and 'y' it worked. How come? I thought that by entering any label for each in |x, y| the puts line would be able to discern this and run the code as long as the labels match up. Please assist.


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


#2

Have you read the error messages?

jsims.rb:8: syntax error, unexpected keyword_alias, expecting '|'
secret_identities.each do |alias, name|
                                ^

#3

The error messages confuse me. haha.


#4

Sure, but have you read it? Or are you not reading it because at a glance it looks confusing?

Which part is confusing? Let's start at the first part, jsims.rb:8:, what might that mean? I think that looks like a file name and a line number, that was pretty straight-forward. Then move on to the next part of the message.

If you avoid reading it then you will not be able to find what it means to say. Read it and identify what stops you from understanding it, and then consider how you can approach that obstacle, for example if there is a phrase in it that you don't understand, then googling that phrase is very likely to produce an answer to what it means.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.