From: Trans Date: 2006-03-19T23:13:49+09:00 Subject: Re: Functor Opinion > Can you elaborate a bit more the benefits and use cases of this class? > Thanks! Sure. I'm aware that technically a Functor is nothing more than a first class function. But Ruby already has a class for this, Proc (not to mention Method). The class I present could more precisely be labeld a "MetaFunctor". But since there's nothing of use to define as Functor in Ruby I just dropped the "Meta" prefix. I'm all ears, if anyone has a truly better name. One could define #call and #[] for this class too, but we don't really want to, because we want to keep as many methods available for passing thru to method_missing as possibe. (Hence the subclass of BasicObject, ie. BlankSlate). I generally use it to create a separate method space for a class. Here's an example of one place I've used it: # facet/kernel/__meta__.rb begin require 'calibre/functor' rescue LoadError require 'facet/functor' end class Object # Returns a Functor that allows one to call any # Kernel method bound to self. # # class A # def object_id ; "OBTUSE" ; end # end # # c = C.new # c.object_id #=> "OBTUSE" # c.__meta__.object_id #=> 6664875832 # def __meta__ @__meta__ ||= Functor.new do |meth, *args| # &blk| Kernel.instance_method(meth).bind(self).call(*args) # ,&blk) end end end Additionally, the Functor can also be used as a quick and simple delegator or proxy. T.