From: Marnen Laibow-Koser Date: 2009-11-20T01:53:57+09:00 Subject: Re: dynamic array? Robert Klemme wrote: > 2009/11/19 Marnen Laibow-Koser : >>> => [] >> >> �def []=(i, value) >> �end >> end >> >> ...and delegate everything else to self.to_a. > > What are you trying to achieve with this? As far as I can see you are > mimicking Array behavior with a Hash. So you have created a sparse > array but not a two dimensional array - which was what the OP wanted > if I understand him properly. Right. The idea was to create a sparse one-dimensional array for the major axis, then populate it with (sparse or not) one-dimensional arrays for the minor axis as necessary. Perhaps I should have explained that in the first place. :) I was trying to avoid the pitfall of your LazyM solution, which appears to use matrix[i, j] instead of matrix[i][j] to address a cell. To my mind this violates POLS. > > As a side note: I'd rather delegate to instead of inherit from Hash. > The DynamicArray is not a Hash. For example, method #size remains in > the interface which might lead to surprises. Probably not a bad idea. This was seat-of-the-pants code. :) > > Kind regards > > robert Best, -- Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org -- Posted via http://www.ruby-forum.com/.