From: Sukhwinder Tambar Date: 2009-04-15T18:51:50+09:00 Subject: Re: how to sort my hash Brian Candler wrote: > Sukhwinder Tambar wrote: >> this is my hash .. i want to sort this by 'business_continuity' > > Actually it's an Array. > > Both Hash and Array are Enumerable, and Enumerable has sort_by method. > > work_orders = work_orders.sort_by { |e| e.business_continuity } > > However, false and true are not comparable, so you need to substitute > some values which do. For example, if you want false to sort before > true, then: > > work_orders = work_orders.sort_by { |e| e.business_continuity ? 1 : 0 > } > > If it's really a hash of key=>record, then > > my_hash.sort_by { |k,v| v.business_continuity ? 1 : 0 } i try my_hash.sort_by { |k,v| v.business_continuity ? 1 : 0 } this give me following error merb : worker (port 4000) ~ undefined method `business_continuity' for nil:NilClass - (NoMethodError) -- Posted via http://www.ruby-forum.com/.