Hash#+?

We have live examples that show that Array#+ is useful. Try grepping
the source tree for /+=? *[/. Another reason for Array#+ is that
arrays are stackable and a + operator matches our expectation and an
analogy to String#+.

well, that’s kind of unfair in that i can’t do the same grep on Hash#|. if it
existed then it would be different story. although i’m sure Array#+ would get
used more. i don’t dispute that.

also i’m not in favor of Hash#+ for the reasons you state. i believe it shoud
be Hash#| since duplicates are overwirtten, which is more in line with with
Array#| where duplicates are removed.

My question is: would it be so a popular demand to add a new method
for Hash? We have been living without it and a.dup.update(b) or
{}.update(a).update(b) will do the job if you need the functionality.
I’m not really against the idea, but just curious as to how it is
going to be used.

the utility that i’ve come across is when i want to keep my original hash but
also make a new one with addional elements. guess that’s obvious. like i
said, i will give real examples as they come up. (there’s a couple in the app
i’m working on, but it is a huge cgi app, and i don’t recall off hand where
they were.) but i’ll let you know.

···

On Monday 03 February 2003 06:06 am, Akinori MUSHA wrote:

At Mon, 3 Feb 2003 21:31:53 +0900, > > Tom Sawyer wrote:


tom sawyer, aka transami
transami@transami.net

Akinori MUSHA wrote:

What’s wrong with ‘hash3 = hash1.dup.update(hash2)’ ? And I’d like to
know how a non in-place version of update is used that frequently.
Would you show us some (live) examples?

by the way, whats wrong with ‘arr3 = arr1.dup.concat(arr2)’ ?

We have live examples that show that Array#+ is useful. Try grepping
the source tree for /+=? *[/. Another reason for Array#+ is that
arrays are stackable and a + operator matches our expectation and an
analogy to String#+.

My question is: would it be so a popular demand to add a new method
for Hash? We have been living without it and a.dup.update(b) or
{}.update(a).update(b) will do the job if you need the functionality.
I’m not really against the idea, but just curious as to how it is
going to be used.

I’ve argued before that this is a natural thing to want when using
keyword arguments, for instance if there are oft-used packages of args
that you want to repeatedly pass with small variations.

Without Hash#+ or Hash#|, one possibly useful idiom might be for methods
that accepts a hash of args to accept two hashes instead, with the
second defaulting to empty, and with the “dup.update” bit hidden from
the caller. Just thought of that. But I’d still prefer to settle on a
concise name for non-destructive hash update.

Mark

···

At Mon, 3 Feb 2003 21:31:53 +0900, >Tom Sawyer wrote:

On Sunday 02 February 2003 11:25 pm, Akinori MUSHA wrote: