I'm trying to look through a hash and compare it's values to an existing string and then when the match is found I want to output its key. I trying to write this in a code block and output the result to the console.
officer.name = "Dave"
@hash = { "Tom" => "97", "Dave" => "98", "John" => "99" }
@hash.each { |key, value| do
if #{key} == officer.name
puts "id: #{value}"
else
puts "no match"
end
}
Right now my console outputs:
id: 97
no match
id: 98
no match
id: 99
no match
I'm trying to get it to output just the value of #{value} based on it's matching #{key}, which in this case would be Dave. So for the above example I want my console to spit just the number 98 or "no match".