Hi,

In message "[ruby-talk:20126] Possible RCR - attr_extern for Mix-Ins"
    on 01/08/23, Stephen White <spwhite / chariot.net.au> writes:

|It might be nice if there were something like:
|
|  module Comparable
|    attr_extern :<=>
|  end
|
|  module Enumerable
|    attr_extern :each, :<=>
|  end

I think it's OK to remain this up to document (and dynamic check), but
if you want to implement this feature by yourself, here's the strawman
implementation.  By the way, Enumerable does not need <=> to be mixed in.

---
class Module
  def required_method(*args)
    unless defined? @required_methods
      need_init = true
      @required_methods = []
    end
    @required_methods |= args
  end
  alias af_orig append_features
  private :af_orig
  def append_features(c)
    af_orig c
    return unless defined? @required_methods
    list = c.public_instance_methods
    for m in @required_methods
      unless list.include? m
	raise TypeError, "method #{m} required to include #{self}"
      end
    end
  end
end

class Class
  undef required_method
end

module C
  required_method :<=>
end

class Foo
  def <=>
  end
  include C
end

class Bar
  include C
end
-- 
							matz.