Le mercredi 01 ao?t 2007 ? 05:44 +0900, Wayne E. Seguin a ?crit :
> Chirag,
> 
> This is how I handle it in my applications:
> 
> # lib/ruby_extensions.rb
> =======================================
> class Module
>    def included_modules
>      ( ancestors - [ Kernel ] ).select { | x | x.class == Module &&  
> x != Kernel }
>    end
> 
>    def directly_included_modules
>      ancestors - superclass.ancestors - [self]
>    end
> 
>    def inherited_modules
>      superclass.included_modules - self.directly_included_modules
>    end
> end
> 
> =======================================
> irb:
> =======================================
>  >> module Module1; end
>    =>nil
> 
>  >> class Class1; include Module1 end
>    =>Class1
> 
>  >> module Module2; end
>    =>nil
> 
>  >> class Class2 < Class1; include Module2 end
>    =>Class2
> 
>  >> Class1.included_modules
>    =>[Module1]
> 
>  >> Class2.included_modules
>    =>[Module2, Module1]
> 
>  >> Class1.directly_included_modules
>    =>[Module1]
> 
>  >> Class2.directly_included_modules
>    =>[Module2]
> 
>  >> Class1.inherited_modules
>    =>[]
> 
>  >> Class2.inherited_modules
>    =>[Module1]
> 
> Actually, I also allow for filtering out of other modules than Kernel  
> but that's not relevant here.
> 
> I sincerely hope this helps.
> 
> =======================================
> (easy irb example paste:)
> =======================================
> module Module1; end
> class Class1; include Module1 end
> module Module2; end
> class Class2 < Class1; include Module2 end
> 
> Class1.included_modules
> Class2.included_modules
> 
> Class1.directly_included_modules
> Class2.directly_included_modules
> 
> Class1.inherited_modules
> Class2.inherited_modules
> 
> 
> --
> Wayne E. Seguin
> Sr. Systems Architect & Systems Admin
> wayneseguin / gmail.com
> 

There is a problem (him ! again ! Arrrrrrg (Monthy Python dixit (yeah
for Monthy Ruby !!! (sorry, I'll try to stop lisp-mod ;)))))
You should try this :
---
module Module1; end
class Class1; include Module1 end
module Module2; end
class Class2 < Class1; include Module1 ; include Module2 end

Class1.included_modules
Class2.included_modules

Class1.directly_included_modules
Class2.directly_included_modules # see this result

Class1.inherited_modules
Class2.inherited_modules
---

--
Etienne Vallette d'Osia