Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Get the modules included into a class object

Reply
Thread Tools

Get the modules included into a class object

 
 
Oliver Saunders
Guest
Posts: n/a
 
      12-04-2008
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.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
David A. Black
Guest
Posts: n/a
 
      12-04-2008
Hi --

On Fri, 5 Dec 2008, Oliver Saunders wrote:

> 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.


Query the class into which you included the module:

class << Bar
ancestors
end


David

--
Rails training from David A. Black and Ruby Power and Light:
INTRO TO RAILS (Jan 12-15), Fort Lauderdale, FL
See http://www.rubypal.com for details
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

 
Reply With Quote
 
 
 
 
Oliver Saunders
Guest
Posts: n/a
 
      12-04-2008
Thanks David.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method lookup for modules included in modules Mark Wilden Ruby 5 05-15-2008 08:24 PM
Help: Get list of modules which are included in the class Chirag Mistry Ruby 22 08-01-2007 04:21 PM
Given an object, how to find public methods in included modules and the parent module? danielbuus@gmail.com Ruby 2 03-21-2007 05:24 PM
accessing class constants in included modules Martin DeMello Ruby 3 11-09-2006 07:56 PM



Advertisments