From: ts Date: 2002-01-01T23:56:48+09:00 Subject: [ruby-talk:29961] Re: Ruby multi-dimensional Hash question?---Any one out there willing to give this questions a try? >>>>> "C" == Chr Rippel writes: C> p t # => {} C> p t[1][0] # => 4 C> p t[0][1] # => 2 C> i.e. you also have to redefine MyHash#inspect, MyHash#keys etc. Why not ? pigeon% cat b.rb #!./ruby class MyHash < Hash def initialize super do |i, j| __default(i, j) end end private def __default i, j i[j] = MyHash.new end end t = MyHash.new t[0][1] = 2 p t[0] p t[0][1] # => 2 t[1][0] = 4 p t[0] p t[1] t[2][3][6] = 12 p t.keys p t[2] pigeon% pigeon% b.rb {1=>2} 2 {1=>2} {0=>4} [0, 1, 2] {3=>{6=>12}} pigeon% Guy Decoux