From: "trans. (T. Onoma)" Date: 2004-10-02T21:57:33+09:00 Subject: Re: ruby-dev summary 24298-24353 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. T.