From: RichardOnRails Date: 2008-05-07T11:55:12+09:00 Subject: Re: get method in Array subclass: where's it defined? On May 6, 5:20 pm, Tim Hunter wrote: > RichardOnRails wrote: > > Hi, > > > Daniel Finnie in another tread help me define a Matrix of essentially > > arbitrary dimension as a subclass of Array. He employs a "get" > > method to handle a splat of the subscripts. I can't figure out where > > this get method is defined. Does anyone have any idea? Code with > > examples follow. > > > Thanks in advance, > > Richard > > > class Matrix < Array > > def [] *args > > if (args.length == 2) && args[0].is_a?(Integer) && args[1].is_a? > > (Integer) > > get(*args) > > else > > super *args > > end > > end > > end > > > 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] > > There is no get method in Array. The get method comes from your original > post, where you defined a get method. Daniel is just saying that under > some conditions your [] method calls the original [] method, under > others (the conditions you define) it calls your get method. > > -- > RMagick:http://rmagick.rubyforge.org/ > RMagick 2:http://rmagick.rubyforge.org/rmagick2.html Ti> m, Thank you very much for your response. > The get method comes from your original > post, where you defined a get method. I didn't interpret it that way. But that interpretation would yield inconsistent results: 1-based indexing wit two subscripts using my get function, and 0-based subscripting with a single subscripts. Secondly, 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 - certainly not mine. So I still wish someone would show where this visible undefined get is, in fact, defined. In fact, it does something with the "splat" operator ... and then I'm lost. So if you've got any other ideas, I'd like to hear them. Again, thanks for your input. Best wishes, Richard