Iterating over Hashes


#1

With the following array:

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

The only answer that is accepted is:
secret_identities.each {|n,tn| "#{n}: #{tn}"}

My answer was this; I may be a head of the class structure, but the values are the same; this should be accepted.
secret_identities.each {|n,tn| puts n+" : "+tn}


#2

Both methods work,

and,

But in the lesson you can only pass if you follow the instructions and write your code based on them in order to pass the SCT. :slight_smile:


#3

I must have missed the description of what this "#{var} structure does?
Just tried to do a google search on it and could not find anything. Can you
to a brief review?


#4

That,

Is a Ruby placeholder that stores values, but it must have an input from where it is receiving the info it will then display#{}


#5

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