ruby simplifier ruby simplifier - 1 month ago 7
Ruby Question

How can i search a value in Ruby Hash Table?

area_dictionary = {
"Alabama" => "205",
"Alaska" => "907",
"American Samoa" =>"684",
"Arizona" => "480",
"Arkansas" => "479",
"California" => "209",
"Colorado" => "303",
"Connecticut" => "203",
"Delaware" => "302",
"Florida" => "239",
"Georgia" => "229",
"Guam" => "671",
"Hawaii" => "808"
}

Answer Source

If you are trying to find the key for a value, you can use the following:

area_dictionary.invert['239']
=> "Florida"

If you are simply trying to get the value for a given key, you can use the following:

area_dictionary['Florida']
=> "239"