Hi --

On Fri, 23 Sep 2005, John Carter wrote:

> Ok, so I'm documenting a Mixin.
>
> Can anyone think of a more sane word / phrase than "The class that it is 
> mixed in to"?
>
> eg. Array is the class that Enumerable is mixed in to.

Array mixes in Enumerable.  Array is that class that mixes in
Enumerable.  Array is the mixer in of Enumerable....

> In particular has anyone devised a standard way of documenting / enforcing 
> the signature that "the class that it is mixed in to" must conform to.
>
> To mix in Enumerable it must have a "each" method that accepts a block.
>
> Perhaps one can devise some code in the module that get's activated at 
> "include" time that checks the instance methods of the class for the required 
> signature.

   module Enumerable
     def self.included(c)
       raise RuntimeError, "#{c} has no 'each'" unless
         c.instance_methods.include?("each")
     end
   end

However... this does too much.  Having #each is not a requirement of
including Enumerable.  All you're doing when you include Enumerable is
putting some methods on the method search path.  Those methods happen
to make calls to #each -- but there's nothing wrong with having a
method that makes a call to #each on your search path, unless you have
no #each and you actually call that method.


David

-- 
David A. Black
dblack / wobblini.net