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? Create a class which inherits from Array and override [] and []= to do your checks. I would have to work to get the syntax right though. Cheers, Ben _____________________________________________________________________________________ Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com