Try this:

>> x = Hash.new([])
=> {}
>> x[:test]
=> []
>> x[:test] << 'this'
=> ["this"]
>> x[:bar]
=> ["this"]

Huh?  It seems that when I index a hash with a new key, it returns the
Hash's default value object, not a copy of it.  So if you modify that,
it modifies the default value, which then effects the default value for
every other new key.

I don't know, I wouldn't call this the "principle of least surprise"...
I was plenty surprised!

-- 
Posted via http://www.ruby-forum.com/.