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"])
Try Enumberable#find
:
categories.find { |key, values|
values.include?("bar")
}.first
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With