I realized that the Ruby stdlib matrix is not modified, i.e., for example,
m = Matrix.zero( 3, 4 )
you can not write
m[0, 1] = 7
But I would like to do it so much ... I can do it with inconvenient programming, for example
def modify_value_in_a_matrix( matrix, row, col, newval )
ary = (0...m.row_size).map{ |i| m.row i }.map( &:to_a )
ary[row][col] = newval
Matrix[ *ary ]
end
... or with a hoax, for example
Matrix.send :[]=, 0, 1, 7
but I wonder, it should be a problem that people face all the time. Is there any standard, common way to do this without having to rape the class using the #send method?
source
share