From: Albert Schlef Date: 2008-05-07T17:06:21+09:00 Subject: Re: get method in Array subclass: where's it defined? RichardOnRails wrote: > m = Matrix[ [10,20,30], [40,50,60], [70,80,90] ]; > puts m [0] [1].inspect # 20 > puts m [2] [0].inspect # 70 > puts m[1].inspect # [40, 50, 60] [...] > my adaptation of Daniel's suggestion, including sub- > classing, works with no definition of get anywhere. And the code runs > without any visible definition of get Your code "works with no definition of get anywhere" because it doesn't utilize this 'get'. When you do "puts m [0] [1]" you aren't triggering your 'get'. That's because "m [0] [1]" is the plain-vanila array indexing; it uses one-dimensional indexing. It's exactly like doing "row = m[0]; row[1]". Multi-dimentional array indexing means: "m[0,1]". and if you tried that you'd trigger the call to 'get', and since it's absence, Ruby would complain. Implementiong your 'get' is no big deal. For a start, replace that "get(*args)" with "self[args[0]][args[1]]". -- Posted via http://www.ruby-forum.com/.