Forum: Ruby on Rails Re: 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 23:04
(Received via mailing list)
Wouldn't that return the objects of class ActiveRecord::Base instead
of the classes themselves?

Looking through the Base.rb, I saw that there's a method called
"subclasses" that's protected.  Just to clarify my original question,
I'm trying to do this from a class outside of ActiveRecord::Base.

> You might query the ObjectSpace.

> Kent.
Luke Amdor (Guest)
on 2005-12-12 23:22
(Received via mailing list)
Try..

objects = []
ObjectSpace.each_object(Class) {|obj| objects << obj if obj.superclass
== ActiveRecord::Base}



Luke

On Mon, Dec 12, 2005 at 04:02:43PM -0500, Andrew O'Brien wrote:
>
> >> http://lists.rubyonrails.org/mailman/listinfo/rails
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

--
Luke Amdor
removed_email_address@domain.invalid

/usr/bin/fortune |

And we can always supply them with a program that makes identical files
into links to a single file.
             -- Larry Wall in <removed_email_address@domain.invalid>
Kent S. (Guest)
on 2005-12-12 23:28
(Received via mailing list)
On Monday 12 December 2005 16:02, Andrew O'Brien wrote:
> Wouldn't that return the objects of class ActiveRecord::Base instead
> of the classes themselves?
>

Not necessarily.

ObjectSpace.each_object(Class) do |c|
  p c if c.superclass == ActiveRecord::Base
end

Note that it assumes that all models have been already loaded.

Kent.
List R. (Guest)
on 2005-12-12 23:38
Kent S. wrote:
> On Monday 12 December 2005 16:02, Andrew O'Brien wrote:
>> Wouldn't that return the objects of class ActiveRecord::Base instead
>> of the classes themselves?
>>
>
> Not necessarily.
>
> ObjectSpace.each_object(Class) do |c|
>   p c if c.superclass == ActiveRecord::Base
> end
>
> Note that it assumes that all models have been already loaded.
>
> Kent.

Won't this miss HappyCustomer < Customer < ActiveRecord::Base ?
Kent S. (Guest)
on 2005-12-13 00:13
(Received via mailing list)
It will. But

ObjectSpace.each_object(Class) do |c|
   p c if c.ancestors.include? ActiveRecord::Base
end

will not.

Kent.
speechexpert (Guest)
on 2005-12-13 00:19
(Received via mailing list)
OK - Here's my issue
My Outlook Expres is getting bogged down by the 50,000 or so emails on
Ruby
and Rails ml's.
I find searching these lists a valuable source of information.
I tried to search the archives directly, and my impression is the search
engine was slow and unreliable.

How do you all solve this problem, since it must be a common issue.
??

Thanks in advance,

John B
Alain R. (Guest)
on 2005-12-13 14:25
(Received via mailing list)
John

Give a try to
     http://www.ruby-forum.com/forum/3

note: it doesn't contain the whole archive, as this project started
recently.

Alain
Todd B. (Guest)
on 2005-12-17 14:41
(Received via mailing list)
Craig Larmer (Guest)
on 2005-12-17 14:41
(Received via mailing list)
For offline access you may be able to use Google Desktop
(desktop.google.com).
It says it has Outlook integration although I haven't used it myself.

Cheers,
CL
This topic is locked and can not be replied to.