From: Run Paint Run Run Date: 2009-05-26T09:54:33+09:00 Subject: [ruby-core:23559] [Bug #1517] Matrix[] Performs No Argument Validation, Confusing Some of Its Instance Methods Bug #1517: Matrix[] Performs No Argument Validation, Confusing Some of Its Instance Methods http://redmine.ruby-lang.org/issues/show/1517 Author: Run Paint Run Run Status: Open, Priority: Normal ruby -v: ruby 1.9.0 (2008-06-20 revision 17482) [i486-linux] The Matrix[] constructor accepts anything as argument. This can cause problems for its instance methods. For example, consider a Fixnum: >> m = Matrix[1] => Matrix[1] This works as you'd expect. But then: >> m.row(0) TypeError: can't dup Fixnum from /usr/lib/ruby/1.9.0/matrix.rb:1132:in `dup' from /usr/lib/ruby/1.9.0/matrix.rb:1132:in `init_elements' from /usr/lib/ruby/1.9.0/matrix.rb:1124:in `initialize' from /usr/lib/ruby/1.9.0/matrix.rb:1117:in `new' from /usr/lib/ruby/1.9.0/matrix.rb:1117:in `elements' from /usr/lib/ruby/1.9.0/matrix.rb:303:in `row' from (irb):20 from /usr/bin/irb1.9:12:in `
' Or: >> m.column_size => 4 Which leads to: >> m.column_vectors => [Vector[1], Vector[0], Vector[0], Vector[0]] If such arguments are accepted, Matrix should coerce them into a matrix. Presumably, the easiest approach would be to have Matrix[1] == Matrix[[1]]. Otherwise, Matrix[] should raise an ArgumentError if it doesn't receive an Array. Ideally, you should only be able to create matrices of Arrays of Numeric-like objects. The current behaviour is non-intuitive, and invites bugs. ---------------------------------------- http://redmine.ruby-lang.org