Ruby 1.9.3 リファレンスマニュアル > ライブラリ一覧 > matrixライブラリ > Matrixクラス > build

singleton method Matrix.build

build(row_size, column_size) {|row, col| ... } -> Matrix

[TODO]

Creates a matrix of size +row_size+ x +column_size+. It fills the values by calling the given block, passing the current row and column. Returns an enumerator if no block is given.

m = Matrix.build(2, 4) {|row, col| col - row }
  => Matrix[[0, 1, 2, 3], [-1, 0, 1, 2]]
m = Matrix.build(3) { rand }
  => a 3x3 matrix with random elements
class Matrix