From: Niklas Frykholm Date: 2001-10-10T05:45:52+09:00 Subject: [ruby-talk:22342] Re: blocks with min and max On Wed, Oct 10, 2001 at 04:45:45AM +0900, Mathieu Bouchard wrote: > On Wed, 10 Oct 2001, Yukihiro Matsumoto wrote: > > Enumerable#min and #max already work like the former, i.e. > > largest = collection.max {|obj1, obj2| obj1.attrib <=> obj2.attrib} > > But I now think I should have chosen the latter. > > largest = collection.max {|obj| obj.attrib} > > Then how would this translate to the latter way? > > largest = collection.max {|obj1, obj2| > r = obj1.foo <=> obj2.foo > r = nil if r == 0 > r || (obj1.bar <=> obj2.bar) > } largest = collection.max {|obj| [obj.foo, obj.bar]} Looks better too. // Niklas