From: Daniel N Date: 2010-02-05T08:02:37+09:00 Subject: Re: Can Ruby Do This? --001636e0a6ecb251d7047ece5436 Content-Type: text/plain; charset=ISO-8859-1 Interesting little problem. Just as a quick belt out, you could do something like this: >> def infinite_hash >> Hash.new{|h,k| h[k] = infinite_hash} >> end => nil >> a = infinite_hash => {} >> a[:foo][:bar][:baz] = "barry" => "barry" >> a => {:foo=>{:bar=>{:baz=>"barry"}}} HTH Daniel On Fri, Feb 5, 2010 at 9:58 AM, Mr Bubb wrote: > In Perl, you can create a hash of arbitrary depth like so: > > $hash->{foo}->{bar}->{baz} = 123; > > I've tried this in ruby: > > hash[:foo][:bar][:baz] = 123 > > but I get nil.= errors > > I could of course do a check for null at each level, but oy, that's so > cumbersome. Is there a ruby way? > > Thanks! > -- > Posted via http://www.ruby-forum.com/. > > --001636e0a6ecb251d7047ece5436--