Find all ActiveRecord::Base subclasses?


#1

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.


#2

You might query the ObjectSpace.

Kent.


#3

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/