From: Rob Biedenharn Date: 2010-03-23T04:49:43+09:00 Subject: Re: Sorting keys of hash based on value 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] } If the hash.size is large, this can be a big performance win, but with just three keys, you won't notice any difference. -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com