From: Mike Stok Date: 2004-04-25T01:44:15+09:00 Subject: Re: pushing hash Joel VanderWerf writes: > Dave Thomas wrote: > > > > On Apr 23, 2004, at 21:49, Pe�a, Botp wrote: > > > >> Is there a reason why "<<" isn't allowed for hashes? > > > > > > Perhaps because hashes aren't ordered, and the common semantics of "<<" > > implies order. > > Can't be the whole story... > > irb(main):001:0> require 'set' > => true > irb(main):002:0> Set.new << 3 > => # I don't think it's ordering so much as Arrays and Sets can have things added to them "unambiguously." The Array gets the new value added to the end, and a set gets a new member added if it doesn't already contain the member. When adding a key/value pair to a hash there are two situations to consider: 1) It's a new key, so just add the key/value pair 2) It's an existing key. What should we do? Replace the old key/valur pair or somehow mutate the existing value? If you just want to replace existing key/value pairs then hash << ['key', 'value'] just means hash['key'] = 'value'. Well, that's my take. Hope this helps, Mike -- mike@stok.co.uk | The "`Stok' disclaimers" apply. http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60 http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA