From: Nikolai Weibull Date: 2005-08-08T04:49:29+09:00 Subject: Re: Adding yet another Array.new form David A. Black wrote: > On Sun, 7 Aug 2005, Christian Neukirchen wrote: > > Nikolai Weibull writes: > > > Lately I've been using the Kernel.returning method from Rails to > > > write it as > > > > > > def a > > > returning ary = [] do > > > ... construct ary by adding elements to it ... > > > end > > > end > > I'd rather vote in favor of including #returning to the Ruby core. > > It is a very helpful method to DRY. > It feels a bit side-effect-dependent-ish, as written. It might be > nicer with a more traditional yield/block param syntax: > > returning [] do |ary| ... end > > That shows more of the separation between the fact that you're > returning an array, and the fact that you're assigning the name ary to > that array for use inside the block. True. It's simple enough to write it that way as well. In fact, implementing it as module Kernel def returning(value) yield value value end end allows us to write it either way, nikolai -- Nikolai Weibull: now available free of charge at http://bitwi.se/! Born in Chicago, IL USA; currently residing in Gothenburg, Sweden. main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}