Find all ActiveRecord::Base subclasses?

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 might query the ObjectSpace.

Kent.

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.
[email protected]
Subversion and Orca training and consulting
http://www.orcaware.com/svn/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs