From: Stefan Rusterholz Date: 2007-07-19T19:21:10+09:00 Subject: Re: array sort_by with nil elements Josselin wrote: > I am using the sort_by command > > @buddies = @user.buddies.compact.sort_by {|item| item.send @criteria} > > > problem arise when one criteria like the user.name is nil the sort > crash.... anyway to avoid it > > thanks a lot for your lights > > joss Simply add a default value (best one that gets sorted in the beginning or the end) @buddies = @user.buddies.compact.sort_by {|item| item.send(@criteria) || default } Regards Stefan -- Posted via http://www.ruby-forum.com/.