From: Robert Klemme Date: 2006-09-20T17:40:12+09:00 Subject: Re: What's the ruby way to sort string with cases in mind On 20.09.2006 09:19, Rimantas Liubertas wrote: >> And implementing your own >> sort routine is not going to be anywhere near as clean as what you've >> got. > > My best try so far is like that: > > a.sort{ |i,j| (i.upcase == j.upcase)? (i<=>j):(i.upcase<=>j.upcase) } > > Not elegant, but not too ugly (or is it?). I've got a feeling there > must be a way to simplify this. a.sort {|i,j| i.upcase == j.upcase ? i <=> j : i.upcase <=> j.upcase} :-) Maybe a bit more efficient: a.sort do |i,j| cmp = i.downcase <=> j.downcase cmp == 0 ? i <=> j : cmp end Cheers robert