From: Robert Dober Date: 2009-05-14T23:46:08+09:00 Subject: Re: [bikeshed] Syntactic sugar idea On Thu, May 14, 2009 at 11:33 AM, Lars Christensen wrote: > On Thu, May 14, 2009 at 4:42 AM, Daniel DeLorme wrote: >> It seems that often an object will be passed into a block only to invoke >> a method of that object: >>  arr.map{ |obj| obj.some_method } >> >> So I had the (weird? stupid?) thought that it would be nice to have some >> syntactic sugar like this: >>  arr.map{ .some_method } > > I sometimes miss Perl's $_. Without a parser change, it could be used > as the default name for block parameters: > >   arr.sort_by { $_.size } >   File.open("logfile", "a") { $_.puts logtext } >   arr.map { foo2bar($_) } > > Then I remember how people abuse it and avoid using appropriately > named variables, and I am again happy about the little extra code I > have to write. > > Forget the $ and you are spelling out a thought I was bearing with me for quite some time, ty Daniel and Joel to bring this up :). I always wanted an implicit _ parameter in blocks, as e.g. 3.times do puts _ end -- Si tu veux construire un bateau ... Ne rassemble pas des hommes pour aller chercher du bois, préparer des outils, répartir les tâches, alléger le travail… mais enseigne aux gens la nostalgie de l’infini de la mer. If you want to build a ship, don’t herd people together to collect wood and don’t assign them tasks and work, but rather teach them to long for the endless immensity of the sea. -- Antoine de Saint-Exupéry