From: Mark Slagell Date: 2003-02-03T22:55:45+09:00 Subject: Re: Hash#+ ? Akinori MUSHA wrote: >At Mon, 3 Feb 2003 21:31:53 +0900, >Tom Sawyer wrote: > > >>>On Sunday 02 February 2003 11:25 pm, 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