From: Robert Dober Date: 2007-08-31T15:03:32+09:00 Subject: Re: python-style decorators On 8/30/07, Keith Rarick wrote: > On 8/30/07, Trans wrote: > > Cool. It will be interesting to see how it turns out. > > Well, I've hit a snag as a result of two properties of ruby: > > 1. If you write "def foo.bar() end", bar is guaranteed to be a > singleton method on something regardless of the value of foo. (You can > verify this on lines 1695-1709 of parse.y and lines 3919-3950 of > eval.c.) > > 2. An unbound method (such as what you get by calling > foo.method(:bar).unbind) can only be bound to an object of the same > type as the original receiver. For singleton methods, this means that > they can only be bound to the very same object. Hmm that is why I put my defs into modules, even one module per method, than I just use the module instead of the method, but honestly your original code is just great if you adapt to the decorator do end idiom you could potentially create a new Module from the block and work with it, but I am not sure what that would be good for, are you not looking for over-perfection here ;)? > If only there were some way to get the body of an unbound method as a > string But there is, oops that is Squeak, not Ruby :( > I could eval it again in the appropriate context. Short of > that, I see no way to make this notation work. > > kr > > Cheers Robert -- I'm an atheist and that's it. I believe there's nothing we can know except that we should be kind to each other and do what we can for other people. -- Katharine Hepburn