Hello --

On Sun, 4 Aug 2002, Tom Sawyer wrote:

> i've been thinking about posting this as an RCR.

I *think* you can do everything you need in this area in Ruby as it
stands, though I may be wrong.

> 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 }

To me that means that key x has value y.  I wouldn't want to have to
figure out that { x, y } is going to blossom into { 'a', 1, 'b', 2 }
(if I'm understanding the idea correctly).

> the Assoc class becomes very useful when you start to build more comlex
> structures (what i would like to use it for):
>
>   c = [ 'a'=>1, 's' ]
>
> this is a very simple example, but without the Assoc you'd have to write
> this as:
>
>   c = { 'a'=>1, 's'=>nil }
>
> adding a useless nil, or

If it's useless, don't add it :-)  The value for 's' will default to
nil, unless your hash has a non-default default.

>   c = [ ['a', 1], 's' ]
>
> whereby you have to use indexes on the association.

Just curl your braces:

  c = [ { 'a',1 }, 's' ]

and you get something which I think does what you want.

> i'm sure there are other uses as well, and i think it may be possible
> that such an Assoc class combined with arrays could ultimatly displace
> regular hashes altogether.

I don't think what you're describing, if I'm understanding it, is a
superset of regular hashes.  But in any case -- why would you want
something to displace hashes?  The usefulness of hashes is pretty well
established.  You can always *add* functionality to Ruby -- it's not a
zero-sum game :-)


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav