From: Surendra Singhi Date: 2006-09-11T00:12:23+09:00 Subject: Re: Matrix modifying and coercion question? Hi, I know it is bad posting on one's own email, but I didn't get any answer. I feel these are reasonable questions to ask. Please help. Regards, Surendra Singhi writes: > Hi, > I was wondering why Ruby Matrix class doesn't creates objects which are > editable? > > That is, > m = Matrix[[2,3,4]] > m[0,0]= 5 > NoMethodError: undefined method `[]=' for Matrix[[2, 3, 4]]:Matrix > from (irb):11 > gives error, > > as a workaround I have seen people/myself opened the matrix class and defined the > '[]=' method such that, '@rows' variable is edited. > > def []=(i,j,val) > @rows[i][j] = val > end > > Is it safe to do this? > Ditto for the Vector class? why are objects of these classes not editable? > > Second, if I want to change the class of an object? Is it possible to do so? > Say, I want an object of Matrix class to automatically changed to DMatrix, > which is a derived class, then how do I do so? > > Thanks for your help. > -- Surendra Singhi http://ssinghi.kreeti.com, http://www.kreeti.com Read my blog at: http://cuttingtheredtape.blogspot.com/ ,---- | "War is Peace! Freedom is Slavery! Ignorance is Strength!" | -- Orwell, 1984, 1948 `----