From: Ross Bamford Date: 2006-01-03T09:37:58+09:00 Subject: Re: Implicit block parameter? On Mon, 02 Jan 2006 22:06:49 -0000, Simon Strandgaard wrote: > On 1/2/06, Simon Strandgaard wrote: >> On 1/2/06, Ross Bamford wrote: >> > On Mon, 02 Jan 2006 20:20:30 -0000, I wrote: >> > >> > > Before I used Ruby, I used Groovy. In some ways they are (well, were >> > > anyway) quite similar, and one feature that I found cool in Groovy >> that >> > > I often miss in Ruby is the implicit (/default/whatever?) block >> > > parameter, 'it': >> > > >> > > [1,2,3].each { puts it } >> > or how about? > > module Kernel > def it > $i > end > end > class Array > alias :each1 :each > def each(&b) > each1{|i| b.call($i = i) } > end > end > > [1, 2, 3].each{ puts it } # 1 2 3 > Cool, didn't consider doing it that way :) I was thinking in more general terms, but this way does get it working with each. I did notice, though, that it doesn't seem too happy with other Enumerable methods (select and collect seem pretty odd)... Cheers, -- Ross Bamford - rosco@roscopeco.remove.co.uk