From: Rick DeNatale Date: 2009-12-06T11:50:52+09:00 Subject: Re: ruby 1.9 and collect On Sat, Dec 5, 2009 at 3:19 PM, David Masover wrote: > On Saturday 05 December 2009 11:40:54 am Raul Jara wrote: >> I was just wondering if >> anyone had any insight into why that change was made, because it feels >> very counter intuitive to me. > > I agree with Rick -- the basic idea here is that all enumerator methods will > turn into Enumerators when called without a block. Well in 1.9 most enumerable methods which take a block will return an enumerator if no block is given but not all. Some, like all? and any? have an optional block which can be used to override the behavior if not block is given of using an identity block, so that collection.all? returns true if none of the elements are nil or false, and any? returns true if any element is not nil or false, another is grep which uses a block to transform matching elements in the results. Other methods like this include sort, min and max. Some of this is for compatibility with 1.8 for methods which already had optional block arguments and didn't return enumerators if the block isn't given. And Ruby 1.9 even added some more methods which work in similar fashion, e.g. count, minmax, one?,and none? But, indeed, most, if not all of the enumerable methods which required blocks in Ruby 1.8 now return enumerables if no block is given in 1.9. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale