In article <91bg97$h5r$1 / nnrp1.deja.com>, <hal9000 / hypermetrics.com> wrote: >Question for you all. > >Suppose you have an array that is growing >more or less unpredictably. You assign an >element that is past the current end, and >you get several new nils as a result. > >My problem: I want to store zeroes, not >nils. > >What I wish (though I'm not advocating an >actual change in Ruby) is to be able to >specify a default value for "new but un- >assigned" elements, much as you can give >a default value for a hash. > >However, I don't want to manually keep >track of when the array gets bigger; I >don't like the option of periodically >scanning it from beginning to end; and >waiting for the array to be completely >built is not an option. > >How would you recommend doing this? One straightforward technique would be to define your own insertion/access/delete methods which perform the necessary substitions/checks, and interact with arrays through those functions. -= Josh