From: James Coglan Date: 2008-09-03T16:14:16+09:00 Subject: Re: How can I prevent include one module multi-times? ------=_Part_18277_2616911.1220426385373 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 2008/9/3 Thomas B. > Zhao Yi wrote: > > I am looking for a method to check whether this module has been > > included. Does Ruby have this feature? > > What's your question? In the subject you ask 'How can I prevent include > one module multi-times?' and this is checked automatically without any > special handling. That's partially correct, but you'll find that the module's included() hook gets called repeatedly: module M def self.included(base) puts "included M" end end class C # prints "included M" 3 times include M include M include M end To check whether M is already mixed into C, the expression 'M > C' returns true if C includes M. You could put this check inside M.included and throw an exception if it's true. ------=_Part_18277_2616911.1220426385373--