Forum: Ruby on Rails Find all ActiveRecord::Base subclasses?

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.
Andrew O'Brien (Guest)
on 2005-12-12 22:04
(Received via mailing list)
I'm wondering was the most Rubyish way to get an array of all
subclasses of ActiveRecord::Base.  This should be possible through
Ruby's reflection capabilities, right?  Or is there a method in
ActiveRecord?

Thanks.
Kent S. (Guest)
on 2005-12-12 22:40
(Received via mailing list)
You might query the ObjectSpace.

Kent.
Blair Z. (Guest)
on 2005-12-12 22:58
(Received via mailing list)
Andrew O'Brien wrote:
> I'm wondering was the most Rubyish way to get an array of all
> subclasses of ActiveRecord::Base.  This should be possible through
> Ruby's reflection capabilities, right?  Or is there a method in
> ActiveRecord?
>
> Thanks.

You could do something like this:

module ActiveRecord
   class Base
     def self.get_subclasses
       @@subclasses
     end
   end
end

ActiveRecord::Base.get_subclasses

ActiveRecord does have a ActiveRecord::Base.subclasses method, but its
private.

Regards,
Blair

--
Blair Z., Ph.D.
<removed_email_address@domain.invalid>
Subversion and Orca training and consulting
http://www.orcaware.com/svn/
This topic is locked and can not be replied to.