I’m new to Ruby, though not to programming in general. So I’m looking
for some of the mechanisms I’m used to finding, and one of them is an
apparatus for Collections (as for example used in C++, OP, VB etc).
I’m hoping that someone can point me in the right direction as to where
functionality can be found, or failing that suggest the most
starting point to create it based on more primitive classes.
The contained objects are user-defined types having multiple fields
members). This in itself seems no problem for Ruby.
Order/Retrieve by index. The collection should stay ordered by
order and support retrieval by integer index. (Sorted collection is a
separate issue, of course.)
Insert/Append/Remove/Delete. (List behavior) Allow appending (at end)
inserting at arbitrary location, and removal or deletion of arbitrary
Find by key: (Dictionary behavior etc) Ability to retrieve member
by supplying a value to match against one of the object’s fields. Often
is simple a Name field on each object, which functions as a key, but at
other times one might want lookup based on some other field or fields.
So far I’ve read plenty that seems related: arrays, hashes, Enumerable,
several related chapters in PickAxe and Ruby for Rails. Although
“collections” are mentioned in many of these sources, I’ve not yet hit
treatment of the ruby way for the Collection basics described above (eg:
on R’s Collection chapter’s description of “insert” is simply replacing
Nth element of an array).
Needless to say, I’d much appreciate comments illuminating this area!
Microsoft Visio MVP