From: Guillaume Cottenceau Date: 2001-09-26T07:43:21+09:00 Subject: [ruby-talk:21693] Re: manipulating "immutable" objects such as Fixnum from within callbacks & al... "Joel VanderWerf" writes: > Guillaume Cottenceau wrote: > > Here's the problem: it happens often that you need to pass "references" to > > objects so that callbacks/functions/etc may modify these objects to their > > convenience, and you will need the modified value afterwards. > > What about using a closure that references local vars in the caller's scope? > (This is discussed a bit on pp.47-8 of the Pickaxe book.) > > def doit > yield 1 > end > > t = 3 > doit { |i| t += i } > puts t > ==> 4 Well it's more generic than that. See my answer to Lyle. I want to use, say, "callbacks" with many parameters and let the "callbacks" manipulate the "values" as they want but still be able to access to new values from outside of the "callbacks". -- Guillaume Cottenceau - http://people.mandrakesoft.com/~gc/