I have two arrays:
@a = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
@b = [a, b, c]
I need to replace n-th column in a with b like:
swap_column(0)
#=> [a, 2, 3]
[b, 5, 6]
[c, 8, 9]
(This is for using Cramer's rule for solving equations system, if anybody wonders.)
The code I've come up with:
def swap_column(n)
@a.map.with_index { |row, j| row[n] = @b[j] }
end
How do I get rid of assignment here so that map returns the modified matrix while leaving @a intact?