On Thu, 04 Sep 2003 20:37:32 GMT "Mark J. Reed" <markjreed / mail.com> wrote: > 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: Yes, that's seemed odd to me at times as well. > module ObjectSpace > class << self > include Enumerable > def each(*args, &block) each_object(*args, &block) end > end > end err....why don't you just alias each to each_object? module ObjectSpace class << self include Enumerable alias :each :each_object end end No mess, no fuss, no greasy aftertaste. > 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. It only seems backwards if you're used to Ruby. :) Jason Creighton