> x=[]; x[:bla][:some_key] does not work? > Posted by Joshua Muheim (josh) on 03.11.2007 21:21 > Hi all > > PHP lets me easily create multidimensional hashes using the following > syntax: > > x = array(); > x["bla"]["some_key"] = true; > > Is Ruby not capable of doing this? > > x = [] > x[:bla][:some_key] = true > > gives me a nil error! > > What wrong here? How about this approach: a = Hash.new{|h,k| h[k]=Hash.new(&h.default_proc) } a[2][1]=2 a[2][2][3]=4 a[3][1][1][1]=1 p a #=> {2=>{1=>2, 2=>{3=>4}}, 3=>{1=>{1=>{1=>1}}}} ( http://snippets.dzone.com/posts/show/4146 ) Cheers, j. k. -- Posted via http://www.ruby-forum.com/.