From: Rick DeNatale Date: 2009-12-06T03:05:33+09:00 Subject: Re: ruby 1.9 and collect On Sat, Dec 5, 2009 at 12:40 PM, Raul Jara wrote: > Under ruby 1.8.6, running > > [1, 2, 3].collect > > results in an array of [1, 2, 3].  In 1.9, however, running > > [1, 2, 3].collect > > results in an Enumerator, which I then have to call .to_a on. > Alternately, I can supply a block > > [1, 2, 3].collect {|x| x } > > and end up with an array.  So I guess that means that the default block > of {|x| x} was removed from the function.  I was just wondering if > anyone had any insight into why that change was made, because it feels > very counter intuitive to me.   I really liked the elegance of opening > up a file and just calling collect to turn it into an array. Actually I find it counterintuitive that Enumerable#collect works without a block in Ruby 1.8. In fact, that little quirk isn't documented in the 1.8 version of the pickaxe. And I would suggest that even more elegant (and intention revealing) than calling collect to turn something into an array would be to use to_a whilch will work on any Enumberable, including files since File is a subclass of IO and IO mixes in Enumerable. -- 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