From: masa@... Date: 2001-04-01T09:41:26+09:00 Subject: [ruby-talk:13402] Re: Multidimensional arrays and hashes? Hi, >From: Lloyd Zusman > Is it possible in ruby to make use of constructs that correspond to > the following Perl constructs? ... > > $array[1][2][3] = 'whatever'; # multidimensional array > > $hash{'a'}{'b'} = 'something'; # multidimensional hash > > I know that I can create classes in ruby which encapsulate this > behavior, but before I re-invent the wheel, I'd like to know if anyone > has already come up with things like this in ruby. class ArrayMD < Array def [](n) self[n]=ArrayMD.new if super(n)==nil super(n) end end a = ArrayMD.new a[1][2][3]="foo" #=> [nil, [nil, nil, [nil, nil, nil, "foo"]]] See also http://www.ir.isas.ac.jp/~masa/ruby/mdary.html M.Tanaka