From: Ruby Admirer Date: 2007-03-01T07:47:38+09:00 Subject: Re: How to get modules included by a class/module (not those from the superclasses) --0-71761601-1172702854=:82589 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Pit, >Including a module in a class that already has been included by one of >its superclasses doesn't change the inheritance hierarchy: > >module M >end > >class P >include M >end > >class C < P >end > >p C.ancestors # => [C, P, M, Object, Kernel] > >class C >include M >end > >p C.ancestors # => [C, P, M, Object, Kernel] > >The only way to create the situation you describe above would be to >include the module in the child class *before* including it in the >superclass. You are absolutely right ! I did not catch this. This seems to be a similar behaviour as for a class variable/method : class B @@var = "Hello" end class C < class B end The class variable @@var is shared/inherited in C. Similar as the case where there is only one include. Conversely : class B end class C < class B @@var = "Hello" end class B @@var = "Goodbye" end The two class variables @@var are different. This is similar as the case where there is an include at each class. I know that this behaviour for class variable/method will change with Ruby 2.0. (A class variable/method will be static to the class) Will it be the same for module inclusion ?? >class Class >def my_own_included_modules >ancestors.inject([]) { |acc, mod| >break acc if mod == superclass >acc << mod unless mod == self >acc >} >end >end This is exactly what I need. > Out of curiosity: why do you need this? I just want to know/understand : - the hierarchy (inheritance) between the Ruby classes - which class really includes which module(s) Thanks a lot. Chauk-Mean. --------------------------------- Don't be flakey. Get Yahoo! Mail for Mobile and always stay connected to friends. --0-71761601-1172702854=:82589--