From: Ken Bloom Date: 2007-12-14T09:40:09+09:00 Subject: Re: Enforce implementation of Module method On Thu, 13 Dec 2007 14:38:34 -0800, Paul wrote: > Let's say I have the following module: > > ------------------------ > module Parenting > > def add_child(a_child) > self.children.push(a_child) > end > > def delete_child(a_child) > self.children.delete(a_child) > end > > def children > # need to implement > end > > end > ------------------------ > > Is there a way to enforce that the 'children' method is implemented in > any class which includes this module? Or do I simply rely on a > commenting convention, as above? It may be the more ruby way to rely on the commenting convention (there's no need to define the children method at all in Parenting, just comment somewhere that it needs to be implemented.) But if checking is really a must, then you can check from Parenting.included as follows: module Parenting def self.included klass raise NoMethodError, "#{klass} must define #children" unless klass.method_defined? :children end end -- Ken (Chanoch) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/