From: "Xavier NoĆ«lle" Date: 2010-07-27T18:42:35+09:00 Subject: Re: Module inclusion and class macro problem 2010/7/25 Rolf Pedersen : > module Interface >  module ILockable >    add_interface_methods :lock, :unlock >  end > >  module IDrivable >    add_interface_methods :drive, :break >  end > end add_interface_methods is not defined for these modules. "include Base" in both should remove this error, but I'm not sure that's what you want in the end. I take the opportunity of this topic to provide my own version of interface implementation and to ask a question about it (if it's off topic, don't hesitate to tell me). My goal is to use your code to perform an automatic interface check and not bother with calling enforce_interface everytime: ===================================== module Interface def inherited(base) puts "#{base} inherited from me" enforce_interface(base) end def enforce_interface(base) instanceMethods = base.public_instance_methods() if (!@interface_methods.nil?()) @interface_methods.each() do |method| throw "No method #{method}" unless instanceMethods.include?(method) end end end def add_interface_methods(*methods) methods.each do |method| (@interface_methods ||= []) << method.to_s end end end class Mother extend Interface add_interface_methods :pwet, :ziou end class Child < Mother def pwet() puts "Method pwet" end def initialize() puts "Child ctor" end end ===================================== This piece of code almost works (so, doesn't work :-)), but ends up (logically) with a "No method pwet" exception. I suppose that it's due to the fact that Child inherits from Mother before to be able to define any method. Is there a way around this problem ? I like Paolo's proposal (which could maybe be extended to allow to check methods arity as well), but dislike the need to call explicitely enforce_interface. -- Xavier NOELLE