class Hoge attr_accessor :x def initialize(v) @x = v end def replace(a) @x = a.x end end def print_array(a) for i in 0..2 do puts "#{a[i][0].x} #{a[i][1].x} #{a[i][2].x}" end end a1 = Array.new(3).map!{Array.new(3){Hoge.new(0)}} a1[1][1] = Hoge.new(1) print_array(a1) puts "" a2 = Array.new(3).map!{Array.new(3, Hoge.new(0))} a2[1][1].replace Hoge.new(1) print_array(a2)