From: Rob Biedenharn Date: 2009-05-20T13:24:47+09:00 Subject: Re: Sorting numbers as strings On May 19, 2009, at 5:51 PM, Johan Holmberg wrote: > On Tue, May 19, 2009 at 5:24 PM, Jack Bauer > wrote: >> You guys are great. I went with Bob's (pick one, hah) since it >> ended up >> being moderately faster than the method I was originally using. >> -- > > Here is a variant similar to the other solutions you already got: > > puts arr.sort_by {|s| s.split(/(\d+)/).each_with_index.map {|x,i| > i.odd? ? x.to_i : x }} > > Works with Ruby 1.9. > > /Johan Holmberg Are you trying to say that you believe some part of a solution that Jack already accepted won't work in Ruby 1.9? (Because they should work fine.) -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com