Ben Bleything
3/6/2007 2:19:00 AM
On Tue, Mar 06, 2007, Giles Bowkett wrote:
> #each enables #collect, doesn't it? It's the core iterator for all
> those other iterator methods.
Good call, hadn't considered that.
> I wanted to throw the horns all metal-style when I first saw this, but
> it doesn't work in irb:
WORKSFORME:
>> class Class
>> def subclasses
>> out = []
>> ObjectSpace.each_object( Class ) {|k| out << k if k < self }
>> return out
>> end
>> end
=> nil
>> IO.subclasses
=> [File, Socket, UNIXServer, UNIXSocket, UDPSocket, TCPServer, TCPSocket, IPSocket, BasicSocket]
I just tried this on a Rails model, and it bombed. I think that's
what's happening to you. You can do Event.send :subclasses, but that's
sort of ghetto.
> but I got identical error output when I tried that. In fact I think I
> just used a synonym for "class Class" by using "Class.class_eval" and
> the whole thing was very cargo cult of me.
hehehe
> Couldn't get Pat's solution to work either!
>
> >>ObjectSpace.each_object {|o| puts o.name if o.is_a?(Class) && o < Event}
> => 55128
This doesn't make sense to me, but without being in your environment
it's useless to try to help :)
Ben