From: Robert Klemme Date: 2007-05-09T23:35:04+09:00 Subject: Re: Implementation of the object.sort method. On 09.05.2007 16:01, Jorge Domenico Bucaran Romano wrote: > Hi, > > I want a demonstrative implementation of the sort method to see how the > callback (passed block) is handled, specifically the comparison result > <=>. > > For example, in the following code: > > puts [4,5,3,2,1].sort do |a,b| > -1 > end > > puts [4,5,3,2,1].sort do |a,b| > 1 > end > > Both print the array sorted down up. I don't understand how this is > possible so I wanted to see a demonstrative (but factual) implementation > of the sort method to see how this parameters are handled. Basically since you do not used block parameters in calculating the block result you cannot expect any particular order. The same code might yield a different ordering with the next version of Ruby because the result is just determined in what order the engine passes pairs to the block. Kind regards robert