From: WATANABE Hirofumi Date: 2003-01-12T18:24:46+09:00 Subject: Re: sorting with the Swartzian transform Hi, Daniel Carrera writes: > This email is simply for the benefit and/or reading pleasure of ruby > hackers. In particular those without a strong Perl background. I just > had to do a Swartzian transform in Ruby and it occurred to me that someone > might benefit from my experience. Ruby 1.8 has Enumerable#sort_by. This method is equivalent to: module Enumerable def sort_by ary = map { |i| [yield(i), i] } ary.sort! { |a, b| a[0] <=> b[0] } ary.map! { |i| i[1] } end end -- eban