From: Ben Bleything Date: 2007-07-20T07:53:17+09:00 Subject: Re: Hash of arrays - whats going on? On Fri, Jul 20, 2007, stephen O'D wrote: > So my problem is solved, but why do you have to do it like this? At > the risk of answering my own question, is it because the block is re- > executed everytime you access a non existent key, creating a brand new > array object, while the first way, it just initialises the value to > the same array each time? The default value you provide is a reference... in this case, you say "use this array as the default value", not "use an empty array as a default value". To see what I mean, try this: empty_ary = [] h = Hash.new h.default = empty_ary h['foo'] << 10 puts empty_ary.size h[foo'] << 20 puts empty_ary.size h['bar'] << 23 puts empty_ary.size h['bar'] << 33 puts empty_ary.size That should show you what's happening. Ben