Hi,
Following three methods would make Ruby's Matrix class (matrix.rb) more
powerful (especially the []= method):
class Matrix
#
# Same as +collect+ but in-place.
#
def collect! # :yield: e
@rows.each{|row| row.collect!{|e| yield e}}
self
end
alias map! collect!
#
# Sets element (+i+,+j+) of the matrix to +value+. That is: row +i+,
# column +j+.
#
def []=(i, j, value)
@rows[i][j] = value
end
#
# Creates an empty +m+ by +n+ matrix.
#
def Matrix.m_by_n(m, n)
new(:init_rows, (0...m).map{Array.new(n)}, false)
end
end
Should we add them?
Regards,
Michael