From: Ian Macdonald Date: 2002-08-07T15:54:29+09:00 Subject: Re: sort problem On Wed 07 Aug 2002 at 14:31:47 +0900, WATANABE Hirofumi wrote: > Ian Macdonald writes: > > :Ruby > :---- > : > :$/ = nil > :foo = gets.split("\n") > :r = /^([a-z]+)([0-9]+)$/ > :foo = foo.sort {|a,b| c,d = r.match(a)[1,2] > : e,f = r.match(b)[1,2] > : c <=> e or d.to_i <=> f.to_i} > :puts foo > > How about Array#<=> ? > > [c, d.to_i] <=> [e, f.to_i] Ah, very elegant indeed! Thanks for this idiom. Ian -- Ian Macdonald | Collaboration, n.: A literary partnership ian@caliban.org | based on the false assumption that the | other fellow can spell. | |