From: Surendra Singhi Date: 2006-09-08T18:47:00+09:00 Subject: Matrix modifying and coercion question? 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. Regards, -- Surendra Singhi http://ssinghi.kreeti.com, http://www.kreeti.com Read my blog at: http://cuttingtheredtape.blogspot.com/ ,---- | Great wits are sure to madness near allied, | And thin partitions do their bounds divide. | | (John Dryden, Absalom and Achitophel, 1681) `----