transfire / gmail.com wrote:
> Right. It's not the #to_proc I'm worried about. I completely agree with
> your assessment and that is exactly what I'm thinking too.

Good to know :)

If some of you want a use case, take this (wrote it a few weeks ago):

   class CachedProc
     def initialize(&proc)
       @proc = proc
       @cache = Hash.new{|cache, args| cache[args] = @proc.call(*args)}
     end

     def call(*args)
       @cache[args]
     end

     alias_method :[], :call

     def to_proc
       # must return a Proc...
       @proc
     end

     def method_missing(name, *args, &block)
       @proc.send(name, *args, &block)
     end
   end

   def cached_proc(&proc)
     CachedProc.new(&proc)
   end

This is fine and all, but doesn't work with iterators and such:

   proc = cached_proc{|obj| expensive_operation(obj)}
   [2, 5, 7, 4, 2, 8, 2].collect(&proc)

Here, the caching doesn't work, because the CachedProc is converted to a 
Proc.


Daniel