On 6/29/06, Dean Strelau <dstrelau / gmail.com> wrote:
> On 6/29/06, Joel VanderWerf <vjoel / path.berkeley.edu> wrote:
> > That doesn't seem to stop Set#<< :
> >
> > irb(main):001:0> s = Set[1,2,3]
> > => #<Set: {1, 2, 3}>
> > irb(main):002:0> s << 4
> > => #<Set: {1, 2, 3, 4}>
>
> That's because the semantics make sense in the context of Set. Set acts like
> an unordered list, not like a Hash.

I disagree. Mathematically, a essentially hash is just a set of key,
value pairs. It's not *just* a set, due to the requirement that keys
be unique, but it's close enough. So if you can "append" to a set by
adding a value, why not append to a hash by adding a pair?

> IMO, appending '5' to a list of numbers {1,2,3,4} makes sense
> while appending a key/value pair doesn't.

I don't see any problem with appending a pair to a Hash, as in my mind
it is equivalent to appending a value to a Set. However, I will point
out that the semantics of the proposed Hash#<< and Set#<< *are*
different. Array#<< and Set#<< each expect a single value; if you give
another Array or Set as the argument, it's added as a unit, rather
than iterating over the contents. The proposed Hash#<< on the other
hand *requires* that the argument be a collection of pairs which can
be iterated over. So there is that difference.

I think the utility can overcome that minor semantic difference, however.

Jacob Fugal