我想通过一个数组中的一个数组,其中包含数组。
该数组应包含 5 个数组,并且在每个数组中还有 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
有谁知道映射是怎么回事?