это то, как вы можете циклически проходить по многомерному массиву, из вашего примера - массив двухмерный (x, y). Я заменил имя массива на arr1
n = 0
arr1 = [["a","b","c", "d"]] +
[[" "]+[n,n+1,n+2].map{ |n| n + 1 }] +
[[" "]+[n+3,n+4,n+5].map { |n| n + 1 }]
# this is how you replace
arr1.each_with_index do |x, xi|
x.each_with_index do |y, yi|
if y.is_a? Integer
x[yi] = 'X'
end
end
end
# this is how you check the result
arr1.each_with_index do |x, xi|
x.each_with_index do |y, yi|
puts "element [#{xi}, #{yi}] is #{y}"
end
end
, и это будет вывод
element [0, 0] is a
element [0, 1] is b
element [0, 2] is c
element [0, 3] is d
element [1, 0] is
element [1, 1] is X
element [1, 2] is X
element [1, 3] is X
element [2, 0] is
element [2, 1] is X
element [2, 2] is X
element [2, 3] is X