On Fri, Sep 05, 2003 at 05:01:50AM +0900, Ryan Pavlik wrote:
> > $ ruby -e 'x = []; ObjectSpace.each_object { |o| x << o if o.class ==
> > Class }; p x'
> <snip>
> 
> This is probably quicker if you do:
> 
>     x = []
>     ObjectSpace.each_object(Class) { |c| x << c }
> 
> ..so you don't have to iterate through thousands of non-Class objects.

It seems odd to me that ObjectSpace doesn't mixin Enumerable, but
that's easily remedied:

	module ObjectSpace
	    class << self
	        include Enumerable
		def each(*args, &block) each_object(*args, &block) end
	    end
	end

Then you can just do this:

	ObjectSpace.find_all { |c| c.class == Class }

Although it is still, as noted above, probably less efficient than
passing Class to each_object.  But it's an aesthetic improvement, 
I think.  I mean, the idea of having to iterate over
a collection with a block that does nothing but an array append, just
to get the collection into array form, seems very backwards to me.

-Mark