From: Robert Dober Date: 2007-01-12T23:30:09+09:00 Subject: Re: RCR Opinion Poll ------=_Part_42970_1622417.1168612204268 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 1/12/07, dblack@wobblini.net wrote: > > Hi -- > > On Fri, 12 Jan 2007, Alexandru E. Ungur wrote: > > >>>> sender: "Robert Dober" date: "Fri, Jan 12, 2007 at 06:56:08PM +0900" > << >> [..] > >> > >> The following is a very common pattern. > >> > >> an_enum.map{ |ele| ele.a_method } > >> > >> I believe that it is sufficiently common to be generalized. > >> > >> There are two idioms I would like to see > >> > >> an_enum.apply_to_all :a_method > > > > Ok, I'm still a newbie, but why not extend map instead of introducing a > > new method? As in: > > > > %w[apples oranges kiwi].map :capitalize # => ["Apples", "Oranges", > "Kiwi"] > > > > Still feels like the good old "map" and acts like it... > > I know it's sometimes hard to dig up the old RCRs (this one goes back > two incarnations) but that was rejected; see > http://oldrcrs.rubypal.com/rejected.html#rcr50. > > The discussion for that RCR included: > > * the suggestion of map(&:meth) > * using "apply" instead of "map" as the name > * rejection by Matz :-) > > The reason for rejection was: "It's too functional so that I'm afraid > it would not work well with OO nature of Ruby. Maybe it's matter of > notation." > > Ruby 1.9 has the map(&:meth) notation. I'm not its biggest fan > (mostly on aesthetic/visual grounds), but it has the advantage of > being more generalized. & invokes to_proc on its operand; and to_proc > for symbols is defined as: > > lambda {|e| e.send(self) } > > There's a lot you have to "just know" to grasp what map(&:meth) is > doing, but basically it does this same thing of distributing a > symbolically-identified method across an enumerable. > > > David > > -- > Q. What is THE Ruby book for Rails developers? > A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) > (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) > Q. Where can I get Ruby/Rails on-site training, consulting, coaching? > A. Ruby Power and Light, LLC (http://www.rubypal.com) > > Matz, David I knew about the &: kludge - I really hate it - but I did not know about the rejected RCR. That's why I asked ;) ty for your time I will not file a RCR of course :( Concerning the old RCRs that are not part of the new site (there are only two RCR if I am not mistaken) is there any way to put them? Can I help? Cheers Robert -- "The best way to predict the future is to invent it." - Alan Kay ------=_Part_42970_1622417.1168612204268--