我正在写一个解决数独难题的类,它有一些二维数组,其中包含指向
Cells
这指向了二维数组。像这样的:
def class Sudoku
attr :rows, :columns, :blocks
def initialize
# build each of the rows, columns, and blocks with a 9x9 map of Cells
end
end
def class Cell
attr :value, :row, :column, :block
def initialize(row, column, block, value)
# set each pointer to its parent row, column and block etc
end
end
问题是,当我做如下事情时:
p = Puzzle.new
在里面
irb
irb> p.rows
=> TONS OF SHIT GETS RETURNED
它输出大量嵌套指针,返回到
内部评级
p.rows[0][0].row[0].row[0].row[0]....
所以我想知道Ruby是否有办法返回这个数组的浅表表示,因为它的所有指针都指向自己。