Sunday, May 14, 2006

Multidimensional arrays 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"]]]