--000e0cd2bfc67393a30470bb9b3f
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

>
> Second, I would argue that there should be + (plus), - (minus), and &
>> (ampersand) methods on hashes, that function the same way they do for
>> arrays
>> (concatenation, difference, and intersection, respectively).
>>
>
> Hash is a very flexible citizen, though. It plays many roles. So how does
> this come out:
>
> {0, 1} - {1}  
>
> {0, 1}
> # if you look at a hash as a set of pairs


I do look at Hash as a set of pairs and I would consider the other uses you
cite to be "non-standard". The first line of RDoc for the class states: "A
Hash is a collection of key-value pairs."

I would argue it's better for +, -, and & to be defined for the standard use
case than to remain undefined in the language.  Those using Hash in a
non-standard way can simply avoid these methods.

You could just as well argue that someone might want [6] - [1] to return
[5], but that wouldn't make sense given that "Arrays are ordered,
integer-indexed collections of any object."


Any objections to nil.to_hash?

Note: in the example I meant to type (hash_or_nil || {}).rehash instead of
(hash_or_nil || nil).rehash

--000e0cd2bfc67393a30470bb9b3f--