From: ara.t.howard@... Date: 2006-03-15T00:38:45+09:00 Subject: Re: how to introduce reference objects into ruby On Tue, 14 Mar 2006, Geert Fannes wrote: > In Ruby, there's the []= and [] operators which you can define together. > The []= can play both the role of subscripting and assignment without > needing any intermediate references. Also, Ruby's subscript operator can > > take any number of arguments. The right-handed value is always the last > in > the list of args. > > class MyMatrix > ... > def []=(i,j,value) > @rows[i][j]=value > @columns[i][j]=value > end > end > > mm=MyMatrix.new > mm[3,5] = 42 > > Indeed, the only drawback is that I have to keep the row and column-wise > elements synchronized, e.g., after an addition or something. For a > matrix with equal row and column sizes, this would mean a duplication of > the needed operations if a reference object existed. But when row "i" is > much longer than column "j", I would rather only lookup and modify the > element (i,j) via the columns, since the Hash llokup for the row will > take much longer. > > Greetings, > Geert. this seems like so much work - why not simply use narray - it does nearly all this already? -a -- share your knowledge. it's a way to achieve immortality. - h.h. the 14th dali lama