From: Tom Sawyer Date: 2002-08-04T08:47:35+09:00 Subject: Re: Assoc Class (Hash Pairs) i recall having a need for it some time ago, but i don't recall off hand what that was. but the use i recently ran across was for building complex hierachies (for gui models) where sometimes you have a "child" object and some times you don't: complex_hierarchy = [ parent => child, childless, another_parent => [ subchildless, subparent => subchild ] ] without this, you either have to use hashes with extraneous nils, or fall back to pure associative arrays. in effect, i think i may be getting at a merger of hash and array, where elements can have index => value associations, but others don't. so that's my need. but the idea of associations in and of themselves strikes me as if they may be useful on their own. ~transami On Sat, 2002-08-03 at 16:19, Harry Ohlsen wrote: > On Sun, 4 Aug 2002 04:05, you wrote: > > i've been thinking about posting this as an RCR. > > > > i would really like to see hash pairs (associations) become real > > objects. i think it would be a very powerful and useful construct. there > > are number of things one could then do. The simpliest obviosuly being: > > > > x = 'a'=>1 > > y = 'b'=>2 > > > > hash = { x, y } > > > > ordered hashes also become a snap, implemented as arrays of these > > associations: > > > > ordhash = [ x, y ] > > > > or, without the above x and y assignments, just > > > > ordhash = [ 'a'=>1 , 'b'=>2 ] > > > > this association class (Assoc?) would of course mixin the comparable > > module. > > This piques my interest, but I'm at a loss to see what one would DO with one > of these. Ie, you obviously see that some types of problems would be made > easier/cleaner by the use of this kind of data structure. > > Can you give an example where having these would be helpful? > > -- ~transami