From: Markus Date: 2004-09-17T03:36:45+09:00 Subject: Re: Changing outside variables inside a proc 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: > > a = "Foo" > b = "bar" > proc = Proc.new { |val1, val2| val1, val2 = "boo", "baz" } > proc.call( a, b ) > > # a and b are still "Foo" and "bar" > > I don't believe this is possible.. but would be very nice for creating a > collect! method for a user-defined object. Thanks I suspect you are right (that it isn't possible), at least without going through some rather extreme contortions. Over all, I'm _glad_ that this is the case (though I must admit I've past parameters in "var" with wild abandon in other languages). 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 -- MarkusQ