Forum: Ruby Get the modules included into a class object

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Be072eb0e9f6f81c20541150cabce3ab?d=identicon&s=25 Ole Ole (ole)
on 2008-12-04 22:20
If I say:

module Foo
   def zim; end
end
class Bar
  class << self
    include Foo
  end
end

# Bar.zim is now available

How can I find out which modules are included into Bar at class-level.

Some attempts:

Bar.included_modules
Bar.class.included_modules
Bar.class.new.included_modules
Bar.ancestors
Bar.class.ancestors
Bar.class.new.ancestors

None of them return anything with Foo in it.
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2008-12-04 22:24
(Received via mailing list)
Hi --

On Fri, 5 Dec 2008, Oliver Saunders wrote:

>
> Bar.class.ancestors
> Bar.class.new.ancestors
>
> None of them return anything with Foo in it.

Query the class into which you included the module:

   class << Bar
     ancestors
   end


David
Be072eb0e9f6f81c20541150cabce3ab?d=identicon&s=25 Ole Ole (ole)
on 2008-12-04 23:23
Thanks David.
This topic is locked and can not be replied to.