From: Trans Date: 2007-09-01T07:05:43+09:00 Subject: Re: python-style decorators On Aug 31, 11:27 am, "Keith Rarick" wrote: > 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. Fudge Nuts! Well, I knew something was a miss. I know Ruby too well to expect that to work ;) And I don't think Pit Captain could even wrangle up a solution to this one. Oh well. Guess it's back to the method_added or block notation. Which is too bad, b/c not you have to make a choice between the readability to the former and the reliability of the later. T.