From: Robert Klemme Date: 2010-03-23T05:40:11+09:00 Subject: Re: Sorting keys of hash based on value On 03/22/2010 08:49 PM, Rob Biedenharn wrote: > On Mar 22, 2010, at 2:40 PM, Aldric Giacomoni wrote: > >> Riccardo Cecolin wrote: >>> Do you want keys or the whole hash? >>> >>> irb(main):015:0> hash.keys.sort { |a,b| hash[b][:happy] <=> >>> hash[a][:happy] } >>> => [:c, :a, :b] >> Of course.. I was trying to make it too complicated. Thanks! >> > > Or the slightly simpler sort_by > > hash.keys.sort_by {|k| hast[k][:happy] } Just for the variety: hash.sort_by {|k,v| -v[:happy]}.map(&:first) Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/