From: Aldric Giacomoni Date: 2010-01-26T03:00:07+09:00 Subject: Re: Nested hash with arrays for default value Glen Holcomb wrote: > I'm trying to find a "nice" way to make a nested hash with an empty > array as > the default "leaf" value. > > Basically I'd like to be able to make an assignment as follows: > > data[2][3][4][5] << 3 > > I can get close but I can't get it right. The data is going to be > coming > straight out of a log so I can't really build the hash ahead of time. > > -- > "Hey brother Christian with your high and mighty errand, Your actions > speak > so loud, I can’t hear a word you’re saying." > > -Greg Graffin (Bad Religion) An empty array? Well.. You can try this: http://trevoke.net/blog/2009/11/06/auto-vivifying-hashes-in-ruby/ As indicated, I didn't come up with this, and it'll take care of creating the hashes for you. You can probably do a check : if nil, then create array.. Then add to array. -- Posted via http://www.ruby-forum.com/.