From: "A. S. Bradbury" Date: 2006-08-02T01:29:53+09:00 Subject: Re: Enumerable On Tuesday 01 August 2006 17:06, A. S. Bradbury wrote: > It depends what you want each to do? Just to wrap @array.each? In that > case, this would work: > def each > @array.each {|item| yield item} > end > > Of course you can do whatever you want to the array item in the block > before you yield it again. > > An alternative technique is as follows: > def each(&block) > @array.each(&block) > end > > I don't know whether there are any real advantages or disadvantages to > either method. Hope this helps Just did a quick benchmark out of curiosity: user system total real Two yields 15.720000 2.220000 17.940000 ( 20.336562) Pass the named block 4.130000 1.020000 5.150000 ( 5.562950) Direct on attr_accessor 3.810000 1.010000 4.820000 ( 5.440259) I passed the block {|i| i} and initialized @array to (1..100).to_a, and ran through 50000 times. Alex