【发布时间】:2013-06-14 01:25:20
【问题描述】:
我想遍历数组中的数组。
该数组应该包含 5 个数组,并且在每个数组中还有五个数组,数字的生成很好,但是当我遍历每个数组以将它们与其他东西映射时,我只得到一个包含 5 个数组的数组。
def random_map
@row = []
@col = []
@map = []
5.times do |row|
5.times do |col|
@c = rand(3)
@d = [@c]
@col << @d
end
@row << @col
@col = []
end
@map << @row
@map.map! do |row|
row.map! do |col|
col.map! do |element|
case(element[0])
when 0
element[0] = "BG"
when 1
element[0] = "B1"
when 2
element[0] = "TR"
end
end
end
end
end
有人知道映射是怎么回事吗?
【问题讨论】:
-
举个例子说明你的输出应该是什么样子。