From: matz@... (Yukihiro Matsumoto) Date: 2001-10-10T03:18:27+09:00 Subject: [ruby-talk:22329] Re: blocks with min and max Hi, In message "[ruby-talk:22325] blocks with min and max" on 01/10/10, Mark Slagell writes: |I don't know if this has been raised before, but I'd like to be able to |supply a simpler block to min and max, taking one argument instead of |two. Currently if objects of a class have some attribute, then finding |the object with the smallest such attribute means doing something like |this: | | largest = collection.max {|obj1, obj2| obj1.attrib <=> obj2.attrib} | |... but this is characteristic of sorting logic, which does not |presuppose an order. min and max have sufficient inherent meaning that |it seems it should make sense to say | | largest = collection.max {|obj| obj.attrib} | |Of course it's not a big deal except when the attribute expression gets |a little lengthy, as I came across in a recent project. | |Any thoughts? 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} You are smarter than me. matz.