Find key of value within array in hash

Viewed 9826

I have a hash categories as following:

categories = {"horeca" => ["bar", "waiter", "kitchen"], 
              "retail" => ["eerste", "tweede"]}

I want to find they key if the value is included in the array of values.

Something like following

categories.key("bar")

which would return "horeca"

as of now I can only get "horeca" if I do

categories.key(["bar", "waiter", "kitchen"])
4 Answers
Related