From: Farrel Lifson Date: 2006-03-10T00:10:38+09:00 Subject: Re: nuby question: sorting with nils Actually you can shorten it a bit further if you use @date ? @date <=> anItem.date : -1 That's due to the fact that in Ruby nil is equivalent to false in conditional expression. Farrel On 3/9/06, Farrel Lifson wrote: > def <=> anItem > @date.nil? ? -1 : @date <=> anItem.date > end > > You can set the -1, to 0, or 1 depdending where you want the objects > with nil @dates placed. > > Farrel > > On 3/9/06, larry wrote: > > if i make an object sortable using <=> as so: > > > > def <=> anItem > > @date <=> anItem.date > > end > > > > and date is nil, it fails. What's the right way to handle nils in this > > scenario? > > > > thanks. > > > > > > > >