From: Paul Date: 2007-03-20T05:25:13+09:00 Subject: Re: Sorting Dates and Times in an array On Mar 19, 2:16 pm, "Rick DeNatale" wrote: > On 3/19/07, Rob Biedenharn wrote: > > > The use of .sort_by causes the keys to be processed once and is > > better for large Arrays than .sort (and if you need .sort!, just do > > @date_array = @date_array.sort_by {...} instead). > > Not exactly the same if you have more than one reference to the Array. > A more general equivalent to sort! would be: > > @date_array.replace(@date_array.sort_by {...}) > Okay, I've tried to understand this but I'm not quite getting it yet. Many of the replies posted here integrate the 'print' and the sorting function, and while normally I'd applaud the efficiency that's not what I need. I need to replace the original contents of the array with the sorted contents. Printing afterwards just let's me confirm that the sorting worked as expected. (By combining the two steps, I'm only getting partial solutions.) I've tried using 'sort_by' but I'm not sure how to apply it to multi- dimensional arrays. What would be the best way to replace the contents if the data array is really large? Should I replace my other sort lines with something other? I noticed that I cannot just change the 'sort' to 'sort_by' in the following line: > @date_array.sort! { |a,b| b[ 7 ] <=> a[ 7 ] } Please let me know. Thanks. Paul.