From: Robert Klemme Date: 2005-11-24T21:37:25+09:00 Subject: Re: Fixnum <=> v.nainar wrote: > I may be missing something obvious . Why is the '<=>' operator not > called when there is no block supplied to sort ?.The Pickaxe book > says ( apropos Array.sort ): > " Comparisons for the sort will be done using the <=> operoator OR > using an optional code block" > How is the comparison done in the second case ? > > class Fixnum > alias oldcmp <=> > def <=>(other) > puts " <=> called with #{self} and #{other} " > oldcmp(other) > end > end > > p [9,1,7,3,5].sort { |a, b| a <=> b} > p [99,11,77,33,55].sort > AFAIK it's an internal optimization. robert