From: Fearless Fool Date: 2010-09-09T08:25:49+09:00 Subject: Re: Problem with Hash of Arrays Gary: All of your suggestions are clean and correct. I apologize for not being clearer. For the "ParserModule.parse(string)" example, I didn't mean to suggest that the slots default to empty arrays (as they did in the previous examples). I was just saying that -- as a developer of a module -- handing a hash table to a user that changes state when accessing its slots via [] can lead to surprising behavior that would be difficult for the user to track down. Of course, you can document the behavior and tell the user to use fetch() rather than []. But isn't it better to create a hash table that doesn't have this behavior in the first place? I still believe the best solution is to avoid hash tables with block initializers. Going back to the OP's question about creating a hash of arrays, we could use your suggestion of: hash.fetch(key) {|miss| hash[miss] = []} << value or the somewhat more succinct: (hash[key] ||= []) << value Either one works for me. Thanks for the suggestions and feedback. - ff -- Posted via http://www.ruby-forum.com/.