[#927] UnboundMethod#to_proc — Dave Thomas <dave@...>

I'm wondering what I can do with a Proc generated by

17 messages 2003/04/06

Re: UnboundMethod#to_proc

From: Michael Granger <ged@...>
Date: 2003-04-08 04:01:28 UTC
List: ruby-core #944
On Monday, Apr 7, 2003, at 20:44 America/Denver, Yukihiro Matsumoto 
wrote:

> In message "Re: UnboundMethod#to_proc"
>     on 03/04/08, Dave Thomas <dave@thomases.com> writes:
>
> |Not necessarily: I don't believe that Unbound should inherit from
> |Method: I think they should both inherit from Object. All they really
> |share is 'arity', and Proc has that too.
>
> Not necessarily indeed.  It's just because implementation
> convenience.
>

It's also convenient when you are testing for a method object and you 
don't care whether it's bound or unbound:

   obj.is_a?( Method )

whereas if one weren't a generalization of the other, you'd have to do:

   obj.is_a?(Method) || obj.is_a?(UnboundMethod)

which seems a bit silly to me.

I also disagree with sharing #arity between unrelated Method and 
UnboundMethod classes as a mixin. A mixin, as I understand them anyway, 
must be abstractable in a way that the arity of a method doesn't seem 
to be; the #arity operation is not incidental to either class, it's 
inherent to them.

--
Michael Granger <ged@FaerieMUD.org>
Rubymage/Believer/Architect
The FaerieMUD Consortium


In This Thread