transfire / gmail.com wrote:
> Trying to be just ducky...
> 
>   class X
>     def to_proc
>       self
>     end
>     def call
>       "x"
>     end
>   end
> 
>   x = X.new
> 
>   def y( &b )
>     b.call
>   end
> 
>   y(&x)
> 
> TypeError: X#to_proc should return Proc
>         from (irb):14
> 
> Why isn't it enough that it x responds to #call? 

Personally, I don't mind that objects given as blocks must define a 
#to_proc method; what I don't like is that the return value must be a 
Proc. It should just check if the return value defined a #call method.

The reason I think the #to_proc method should be there is that the 
semantics of #call heavily depends on the context in which it's in:

   class PhoneNumber
     def call; end
   end

#to_proc is by convention only defined on objects that in some way think 
of themselves as procs -- #call can be defined on a lot of objects, for 
a variety of reasons.

That may not be completely "ducky", but I think it's common sense.


Daniel