[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:01979] Re: Iterating over all instances of a class

From: "David Douthitt" <DDouthitt@...>
Date: 2000-03-17 16:37:22 UTC
List: ruby-talk #1979
| In article <s8d205e0.020@email1.cuna.com>,
|     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?


In This Thread

Prev Next