From: Julian 'Julik' Tarkhanov Date: 2006-08-28T00:57:38+09:00 Subject: Re: Keep track of all instances of a class without losing GC? On 27-aug-2006, at 16:45, Jez Stephens wrote: > I want to be able to keep track of all instances of a class using > something simple like this: > > Class Thing > @@allthings = [] > > def initialize > @@allthings.push self > end > end weakref might be of help indeed, you also can use lookups (3 extra lines): class Thing @@things = [] def self.things @@things.map{ | id | ObjectSpace._id2ref(id) } end def initialize @@things << self.object_id end end After that you might get lost references when object get garbage collected, but if you don't need that - what's the point ? :-) -- Julian 'Julik' Tarkhanov please send all personal mail to me at julik.nl