[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Changing outside variables inside a proc

Nate Smith

9/28/2004 1:05:00 PM

On Thu, 2004-09-16 at 14:36, Markus wrote:
> On Thu, 2004-09-16 at 10:28, Nate Smith wrote:
>
> > Is there any way to change an outside-scoped object inside a proc? Such
> > as:
> > ........

> Why do you think this is needed (or nice) for writing a collect!
> method? Why cant you just write something like:
>
> class My_collection_class
> def [](k)
> :
> end
> def []=(k,v)
> :
> end
> def each_key
> :
> end
> def collect!
> each_key { |k| self[k] = yield(self[k]) }
> end
> end

Very true indeed (that works great). I was more thinking about
collecting for the key and the value in one swoop, but that may be more
trouble than it's worth.

Nate