From: jweirich@... Date: 2001-09-26T20:09:25+09:00 Subject: [ruby-talk:21716] Re: manipulating "immutable" objects such as Fixnum from within callbacks & al... >>>>> "Guillaume" == Guillaume Cottenceau writes: Guillaume> Here's the problem: it happens often that you need to Guillaume> pass "references" to objects so that Guillaume> callbacks/functions/etc may modify these objects to Guillaume> their convenience, and you will need the modified value Guillaume> afterwards. Not that I particularly recommend this approach, but the following will actually work ... class Pointer def initialize(&block) @getter = eval("lambda { #{yield.id2name} }", block) @setter = eval("lambda { |value| #{yield.id2name} = value }", block) end def value @getter.call end def value=(new_value) @setter.call(new_value) end end def increment(a_pointer) a_pointer.value = a_pointer.value + 1 end x = 1 increment(Pointer.new{:x}) puts x # => 2 Truthfully, this borders on the bizarre. I've never found a need for this in real life code. For some background, see ... http://c2.com/cgi/wiki?SinisterSchemeSampleInRuby -- -- Jim Weirich jweirich@one.net http://w3.one.net/~jweirich --------------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)