From: Robert Dober Date: 2007-07-26T02:38:30+09:00 Subject: Re: Help: Get list of modules which are included in the class On 7/25/07, dohzya wrote: > Le mercredi 25 juillet 2007 � 22:58 +0900, Robert Dober a �crit : > > > You're right, but it can be fixed :) > > no it cannot :(, look at C4 below > > > --- > > > class Class > > > def included_modules > > > c = self > > > all = c.ancestors - [c] > > > bad = all.map {|a| > > > a.ancestors - [a] > > > } > > > # Module#superclass doesn't exist > > > bad << c.superclass if c.is_a? Class > > > all - bad.flatten > > > end > > > end > > > > > > module M1; end > > > module M2; include M1; end > > > module M3; end > > > module M4; include M3; end > > > module M5; end > > > module M6; include M5; end > > > module M7; end > > > class C1; include M2; end > > > class C2 > > class C3 > class C4 > ************************************* > > M5 will not show up. > > This was the first and not fixable (with this solution) problem :) > module re-included are hidden > > --- > module M1; end > module M2; end > module M3; include M2; end > class C1; include M1; end > class C2 < C1; include M1; include M2; include M3; end > --- > only [M3] will show up > > too bad... yeah the information just is not in the ancestor array :( but it was a nice try ;) > > -- > Etienne Vallette d'Osia > > > -- I always knew that one day Smalltalk would replace Java. I just didn't know it would be called Ruby -- Kent Beck