From: Robert Klemme Date: 2004-10-03T19:49:55+09:00 Subject: Re: ruby-dev summary 24298-24353 "trans. (T. Onoma)" schrieb im Newsbeitrag news:200410020857.29176.transami@runbox.com... > On Friday 01 October 2004 01:24 pm, gabriele renzi wrote: >> trans. (T. Onoma) ha scritto: >> > In that case you might want this: >> > >> > # functor.rb >> > >> > class Functor >> > def initialize(&func) >> > @func = func >> > end >> > def method_missing(op, *args) >> > @func.call(op, *args) >> > end >> > end >> > >> > Shhh... Don't tell anyone. It's my favorite secret weapon ;) >> >> Ok, I don't have an use for this, but, well, indeed very cool :) > > Here's one related to a recent thread: > > class Object > def supers(klass=self.class.superclass) > raise ArgumentError if ! self.class.ancestors.include?(klass) > Functor.new do |meth, *args| > klass.instance_method(meth).bind(self).call(*args) > end > end > end > > Hmm, maybe should cache the functor for efficiency. Might not be a good idea since the method can change. Currently I don't know a way to detect that change as those method methods always return new instances. Apart from that I still think that explicit super class method invocation other than a method invocing its own super implementation is a code smell that indicates the need for a refactoring. Cheers robert