Hi -- On Thu, 21 Jun 2007, Alexander Presber wrote: > I would like to think of the Enumerable mixin as an interface, describing the > general concept of "enumerability". > Rejecting and selecting certain elements of an enumerable set certainly > belong to this concept. > > As I see it, a general recipe for selecting would be: > 1) iterate (hence the need for enumerability) vfer the given set and check > the return value of the block for each element. > 2) if true, keep, otherwise drop > 3) return the resulting set, keeping all other properties (including class) > intact The question, though, is the representation of the "set". Any class that mixes in Enumerable and defines #each can have a select operation, and there's no constraint that says that such a class has to be a collection. So you can't guarantee that the class provides a container in which an instance can return a smaller version of itself. >>>> Of course Hash#select could act differently but that a) might hurt duck >>>> typing >>> >>> I fail to see why, could you give an example? >> >> Anything that depends on the output having array-like behaviors: >> >> selected = enum.select(&select_block).flatten > > I don't get what that has to do with duck typing. > > The possibility to _flatten_ something requires it to be an Array-duck, not > an Enumerable-duck. That is why flatten is part of Array. > Nobody should expect the result of Enumerable#select to be flattenable. Well, that's what we're discussing :-) I expect #select to return an array, so it's flattenable. But now I think we're going in circles. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)