On Jan 26, 2006, at 1:59 PM, Jon Baer wrote:

> Going through pick-axe and was just wondering if there was a one  
> liner for something such as this that I may have missed:
>
> h2 = Hash.new
> h1 = {"foo1"=>"bar1", "foo2"=>"bar2"}
> query = h1.select { |k,v| v == "bar2" }
> query.each do |result|
>   h2[result[0]] = result[1]
> end
> p h2

Like this?

 >> h1 = {"foo1"=>"bar1", "foo2"=>"bar2"}
=> {"foo1"=>"bar1", "foo2"=>"bar2"}
 >> h2 = Hash[*h1.select { |k, v| v == "bar2" }.flatten]
=> {"foo2"=>"bar2"}

Hope that helps.

James Edward Gray II