From: Keith Rarick Date: 2007-09-01T03:27:55+09:00 Subject: Re: python-style decorators On 8/31/07, Trans wrote: > However, even though I think such a change is a good thing to pursue That sounds good to me. It would easily solve this problem and make many other things possible. > (I'm even tempted to revive Suby just to offer this one distinct > feature), I offer this: > > [snip] > > Honestly, I half-expect I'm delusional, b/c I'm not sure how this > manges to work, but it seems to do so. Maybe you can use it as a > jumping board. That almost works! See why: class X class Foo def initialize(klass) @klass = klass @x = 5 end def singleton_method_added(meth) return if meth == :singleton_method_added m = method(meth) @klass.send(:define_method, meth, m.to_proc) end end def initialize @x = 3 end def self.fooized @foo ||= Foo.new(self) end def fooized.try 10 + @x end end p X.new.try If try were really bound to the instance of X, this would produce 13. But it produces 15. I was going to try dumping the method object with the Marshal module as a roundabout way of getting the source code, but that doesn't work either. kr