From: grzegorz.jakubiak@... Date: 2017-12-11T12:13:38+00:00 Subject: [ruby-core:84158] [Ruby trunk Feature#14151] Make Matrix#[]= public method Issue #14151 has been updated by greggzst (Grzegorz Jakubiak). marcandre (Marc-Andre Lafortune) wrote: > The method []= as it is written is also dangerous as it doesn't do any type checking. Try calling `m[1..2, 1..2] = 42` for example... @marcandre I called it using send and it didn't change a thing in my 3x3 Matrix. So what you probably mean we'd have to add this functionality so it works as in arrays when you pass a range. My example (at the end I'm setting one element) : ~~~ ruby m = Matrix[[1,2,3],[1,2,3],[1,2,3]] => Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]] m.send(:[]=, 1..2, 1..2, 5) => 5 m => Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]] m.send(:set_element, 1..2, 1..2, 5) => 5 m => Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]] m.send(:[]=, 1, 1, 5) => 5 m => Matrix[[1, 2, 3], [1, 5, 3], [1, 2, 3]] ~~~ ---------------------------------------- Feature #14151: Make Matrix#[]= public method https://bugs.ruby-lang.org/issues/14151#change-68264 * Author: greggzst (Grzegorz Jakubiak) * Status: Feedback * Priority: Normal * Assignee: marcandre (Marc-Andre Lafortune) * Target version: ---------------------------------------- I don't even understand why this method hasn't been public since the beginning. I've come to a point when I have to create a matrix in a specific way using row and column indices and I can't use #build with a block because then indices go from the beginning of matrix whereas I have to from the center of the matrix. So what I wanted to do is to create a zero matrix and the fill it in a proper way but I can't without using #[]=. I know I can reopen class and that's what I'm doing but this just doesn't make sense. If we can change elements in an array like so using #[]= then why matrices can't use that as well? -- https://bugs.ruby-lang.org/ Unsubscribe: