From: "Brett W. McCoy" Date: 2001-04-09T00:11:45+09:00 Subject: [ruby-talk:13559] Re: array question On Sun, 8 Apr 2001, Tjabo Kloppenburg wrote: > hi, > > there's something I don't understand: > when coding: > > arr = Array.new > arr[1000] = 1 > puts arr.size > > -> 1001 > > I expected to get "1" - because there's only one element in the array. > Is this a bug, or a feature? :-) If you put a value into element 1000, it will automagically create an array of that size (0 .. 1000), 1001 elements. This might seem a little odd, but with dynamically allocated arrays, it's correct behavior. -- Brett http://www.chapelperilous.net/btfwk/ ------------------------------------------------------------------------ No excellent soul is exempt from a mixture of madness. -- Aristotle