Google Groups Home
Help | Sign in
Message from discussion get modules that are in a class?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
dbl...@wobblini.net  
View profile
 More options Jul 8 2007, 7:32 am
Newsgroups: comp.lang.ruby
From: dbl...@wobblini.net
Date: Sun, 8 Jul 2007 20:32:49 +0900
Local: Sun, Jul 8 2007 7:32 am
Subject: Re: get modules that are in a class?
Hi --

On Sun, 8 Jul 2007, Travis D Warlick Jr wrote:

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

>>> http://www.ruby-doc.org/core/classes/Module.html#M001697

>> What about within a class?

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

It's not exactly an inclusion thing.  Class objects already respond to
#included_modules, because Class inherits from Module.

> 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

That will work with any object:

   "".class.included_modules

etc.  It's not dependent on your having included a module.

David

--
* Books:
   RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242)
   RUBY FOR RAILS (http://www.manning.com/black)
* Ruby/Rails training
     & consulting:  Ruby Power and Light, LLC (http://www.rubypal.com)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google