From: Just Another Victim of the Ambient Morality Date: 2006-09-11T11:40:23+09:00 Subject: Re: Matrix "M. Edward (Ed) Borasky" wrote in message news:4504A5A6.9050900@cesmail.net... > dblack@wobblini.net wrote: >> Hi -- >> >> On Mon, 11 Sep 2006, v.srikrishnan@gmail.com wrote: >> >>> Hi all, >>> a) Is there a way to create a non-square matrix in ruby? >>> b) How does one set any arbitrary element of an array? >>> >>> I searched for these bu there was a post about 3 years back, if >>> anything has been done it would be better to use that rather than >>> something i should write! >> >> Check out the Matrix class -- look for matrix.rb in the Ruby >> distribution. >> > You can only set an arbitrary element of a Matrix when it is created. > Once created, you can't change any of the entries. The []= operator does seem conspicuously missing. If anyone knows why this was (obviously) deliberately left out, please say something! Of course, if this is useful to you, you can always add it, yourself! I think it would go something like this... require 'matrix' class Matrix # are for kids! def []= (i, j, v) @rows[i][j] = v end end