On 14-Mar-06, at 5:28 PM, Edward Faulkner wrote:

> On Wed, Mar 15, 2006 at 07:23:46AM +0900, Pavel Smerk wrote:
>> However, Jim Weirich's (a[1] <=> b[2]).nonzero? || a[2] <=> b[2]  
>> seems OK
>
> I don't think that actually does what you want.  The test should
> return -1 if a[1] is less than b[2], but instead it will return
> "true".
>

Are you sure?
------------------------------------------------------- Numeric#nonzero?
      num.nonzero?    => num or nil
------------------------------------------------------------------------
      Returns _num_ if _num_ is not zero, +nil+ otherwise. This behavior
      is useful when chaining comparisons:

         a = %w( z Bb bB bb BB a aA Aa AA A )
         b = a.sort {|a,b| (a.downcase <=> b.downcase).nonzero? || a  
<=> b }
         b   #=> ["A", "a", "AA", "Aa", "aA", "BB", "Bb", "bB", "bb",  
"z"]

Mike

-- 

Mike Stok <mike / stok.ca>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.