From: Lee Griffiths Date: 2008-08-05T22:33:59+09:00 Subject: Re: Matrix class: How to set a single element ? Marcio Braga wrote: > Todd Benson wrote: >> On Mon, Aug 4, 2008 at 10:24 PM, Marcio Braga >> wrote: >>> undefined method '[]=' for Matrix[[11, 12], [21, 22]]:Matrix >>> (NoMethodError) >> >> You have to open the class and define the method as in the example... >> >> class Matrix >> def []=(i, j, x) >> @rows[i][j] = x >> end >> end >> >> Todd > > Perfect! Thank you. > > Quick comment: Why this method is not already pre-defined in the Matrix > class ? Matrix and Vector are, in my opinion, pretty poor classes. You can't even divide a Vector by a scalar quantity (you have to v*1/a instead. :/). There's a lot of common things they don't support and lots of the methods do things in strange ways (at least they look strange to me..). The initilization of Vectors is pretty odd. Lots of pointless method hopping (along with passing a symbol....why?!). -- Posted via http://www.ruby-forum.com/.