On Fri, 15 Dec 2000 07:40:01 +0900, 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. quick hack: class Array attr_accessor :default_value alias oldidx []= def []=(*arg) if arg.size == 3 return oldidx(*arg) end start, elem = arg if start > size fill @default_value, size, (start - size) end oldidx start, elem end end a = [1, 2, 3] a.default_value = 0 a[7] = 42 p a #=> [1, 2, 3, 0, 0, 0, 0, 42] Michel