From: Robert Klemme Date: 2010-02-11T21:33:38+09:00 Subject: Re: Find has key from a value 2010/2/11 John Butler : > I cant seem to figure this out, if i have a hash value can i then get > the key thats associated to that value. > > So the hash.has_value(val)? method will return true or false if that > value exists in the hash but what i need to know is what is the key for > the particular value. > > Any ideas? Hash#rassoc irb(main):001:0> {:foo=>:bar}.rassoc :bar => [:foo, :bar] irb(main):002:0> {:foo=>:bar}.rassoc :foo => nil irb(main):003:0> You can do key, = hash.rassoc your_value Note, the comma is important. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/