Logan Capaldo wrote:
> Pros:
> - No more worrying about your custom dispatching in potentially 3
> different places, you just write the code once.
> Cons:
> - Increased complexity of method calling semantics
> - Not backwards-compatible at all. (This is a biggee).
> 
> So any thoughts? Anything wrong with this that I missed?

Hmmmm ... an interesting idea.  It is possible to provide this in a 
backwards compatible fashion too.  Create a new method (say 
"replacement_lambda") that returns nil for Object and rewrite 
method_missing and respond_to? to use check for a replacement_lambda. 
If one is not found, then just perform the original logic.

Somethind like this ...

-------------------------------------
module Kernel
  def replacement_lambda(sym)
    nil
  end

  alias original_method_missing method_missing

  def method_missing(sym, *args, &block)
    if lamb = replacement_lambda(sym)
      lamb.call(sym, args, block)
    else
      original_method_missing(sym, args, block)
    end
  end

  alias original_respond_to? respond_to?

  def respond_to?(sym)
    replacement_lambda(sym) || original_respond_to?(sym)
  end
end
-------------------------------------

I don't particularly like the name "replacement_lambda", and I'm still 
deciding if I like the extra complexity or not.  But an interesting idea 
nevertheless.

--
-- Jim Weirich

-- 
Posted via http://www.ruby-forum.com/.