Wayne E. Seguin wrote: > On Jul 07, 2007, at 22:00 , Aaron Smith wrote: >> is it possible to find out what modules have been included inside of a >> class?
> Yes Aaron it is, via the method "included_modules"
Aaron Smith wrote: > Wayne E. Seguin wrote: >> On Jul 07, 2007, at 22:00 , Aaron Smith wrote: >>> is it possible to find out what modules have been included inside of a >>> class?
>> Yes Aaron it is, via the method "included_modules"
> module TestModule > def say_something > puts "SOMETHING" > end > end
> class Test > include TestModule > end
> t = Test.new > puts t.included_modules
Remember that when you include the module, you're including _all_ the module's methods (including Module#included_modules)
So, use self.class to get the Class object of the current instance (this will work from the included modules also), so you should be able to do:
self.class.included_modules
And a debugging efficiency tip: use the Array#sort method with the Module#included_modules to sort the list of included modules for easier viewing. I use this all the time in IRB. (This also works with Class#methods and all the like)
irb(main):001:0> YourClass.methods.sort
-- Travis Warlick Operis Systems, LLC Lead Developer
> And a debugging efficiency tip: use the Array#sort method with the > Module#included_modules to sort the list of included modules for easier > viewing. I use this all the time in IRB. (This also works with > Class#methods and all the like)
> Aaron Smith wrote: >> Wayne E. Seguin wrote: >>> On Jul 07, 2007, at 22:00 , Aaron Smith wrote: >>>> is it possible to find out what modules have been included inside of a >>>> class?
>>> Yes Aaron it is, via the method "included_modules"