From: Keith Rarick Date: 2007-08-30T08:40:49+09:00 Subject: Re: python-style decorators On 8/29/07, Daniel DeLorme wrote: > what about: > class C > decorate :memoized do > def ... > end > end > > That makes the implementation much more simple and solid than relying on > method_added which may be incorrectly overridden somewhere. I like that. I think the gain in robustness more than offsets the slight degradation (IMO) in readability. What would it look like for class methods? Something like this? I don't know how I would implement example 2 below. class C # Example 1 (instance method) decorate :memoized do def tak(x, y, z) return z if x <= y tak(tak(x - 1, y, z), tak(y - 1, z, x), tak(z - 1, x, y)) end end # Example 2 (class method) decorate :memoized do def self.tbk(x, y, z) return z if x <= y tbk(tbk(x - 1, y, z), tbk(y - 1, z, x), tbk(z - 1, x, y)) end end # Example 3 (class method) class << self decorate :memoized do def tck(x, y, z) return z if x <= y tck(tck(x - 1, y, z), tck(y - 1, z, x), tck(z - 1, x, y)) end end end end kr