From: David Douthitt Date: 2000-03-17T10:37:22-06:00 Subject: [ruby-talk:01979] Re: Iterating over all instances of a class | In article , | David Douthitt writes: | | > I just KNOW this is related to "collection" somehow, or that there is a way to do this. | >However, the way I do it now is to create an array of instances, | >but this creates some unwieldy *.find{ |i| .... } sequences and | >worse. Can't I do a find over instances of a class? | | all_instances_of_Foo = [] | ObjectSpace.each_object(Foo) do |obj| | all_instances_of_Foo << obj | end Cool! I do think you meant "ObjectSpace" and "all_instances..." in lines 1 and 2. However, I think I found a better way to do what I want. I'm creating a special subclass of Array, and piling everything in there. A problem with doing it the way you described (in my case) is that every object has a "name" and has to be named. In an array, the objects are "anonymous" (no name, just an index). So my Array subclass is better for what I want. Maybe I can generalize it and actually give something back to you all! Say...... what I'm looking for wouldn't be what Smalltalkers call a "collection" would it?