From: James Coglan Date: 2008-09-03T17:35:23+09:00 Subject: Re: How can I prevent include one module multi-times? ------=_Part_18958_26699980.1220431252630 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 2008/9/3 Sebastian Hungerecker > Roger Pack wrote: > > Zhao Yi wrote: > > > I am looking for a method to check whether this module has been > > > included. Does Ruby have this feature? > > > > Might try parsing Object.constants for the module name. > > Why? That only tells you whether that module exists (and it only tells you > that when the module is in the top-level namespace). It doesn't tell you > whether that module has been included into anything. Ah, I think I misunderstood the question. I wrote this a while ago to find all the descendants of a module: class Module def descendants classes = [] ObjectSpace.each_object do |klass| next unless Module === klass classes << klass if self > klass end classes end end So, a module has been included if mod.descendants.size.nonzero? ------=_Part_18958_26699980.1220431252630--