Project

General

Profile

Actions

Feature #2771

closed

Matrix: constructor to build with block

Added by marcandre (Marc-Andre Lafortune) over 12 years ago. Updated about 11 years ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-core:28272]

Description

=begin
I believe the following simple constructor could be a helpful addition to matrix.rb

class Matrix

Creates a matrix of +row_size+ x +column_size+.

It fills the values by calling the given block,

passing the current row and column.

m = Matrix.build(2, 4) {|row, col| col - row }

=> Matrix0, 1, 2, 3], [-1, 0, 1, 2

m = Matrix.build(3) { rand }

=> a 3x3 matrix with random elements

def self.build(row_size, column_size = row_size)
raise ArgumentError if row_size < 0 || column_size < 0
return to_enum :build, row_size, column_size unless block_given?
rows = row_size.times.map do |i|
column_size.times.map do |j|
yield i, j
end
end
new rows, column_size
end
end
=end

Actions #1

Updated by keiju (Keiju Ishitsuka) over 12 years ago

=begin
Hi, Marc-André

Please commit it.
=end

Actions #2

Updated by marcandre (Marc-Andre Lafortune) over 12 years ago

  • Status changed from Open to Assigned
  • Assignee changed from keiju (Keiju Ishitsuka) to marcandre (Marc-Andre Lafortune)

=begin

=end

Actions #3

Updated by marcandre (Marc-Andre Lafortune) about 12 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r27315.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Actions

Also available in: Atom PDF