From: Florian Frank Date: 2006-04-14T12:27:49+09:00 Subject: Re: Rubyesque way to do multiple <=> Victor Shepelev wrote: >def <=> (other) > res = ComplexCustomComparator.compare(sex, other.sex) > return res if res != 0 > > #if they have the same sex, do other comparisons >end > >Foooooo! > >How can I do the former in more elegant way? > > def <=> (other) ComplexCustomComparator1.compare(sex, other.sex).nonzero? || ComplexCustomComparator2.compare(age, other.age).nonzero? || # ... ComplexCustomComparatorn.compare(foo, other.foo) end