From: Gregory Brown Date: 2007-08-10T06:39:48+09:00 Subject: Re: Using the spaceship operator to compare nil? On 8/9/07, Dan Croak wrote: > I forgot to mention that this is called, for example, with: > > assert_ordered_by :last_name, :users, "<=" > > I'm also moving away from using the spaceship operator into > conditional logic land because I was having difficulty dealing > (mentally) with comparing nil to various types (dates, strings, > integers, etc.). Here's the latest non-working code... :/ Try this: has_nil, doesnt = collection.partition { |r| r.send(attribute).nil? } you can then sort only the ones that have a meaningful sort value and then rejoin as needed based on the direction, e.g. for one directed you want: doesnt.sort + has_nil and for another you want has_nil + doesn't.sort hope that helps. Excuse the incomplete code :)