From: Mark Woodward Date: 2007-01-07T19:31:57+09:00 Subject: Re: Array questions On Thu, 04 Jan 2007 11:56:09 +0100, Robert Klemme wrote: > On 03.01.2007 23:58, Mark Woodward wrote: >> I suspected that but I couldn't understand how/why this could be done >> with a size 0. >> >> @paths = Array.new(0,Array.new(0)) to me reads as "create a new array >> with nothing in it and make that nothing reference another empty >> array?" >> ie [] > > Nothing cannot really reference to anything, can it? Not that I'm aware of ;-). > >> @paths = Array.new(1,Array.new(0)) This, if my logic's right, reads as >> "create a new array with a single element that's an empty array. >> ie [[] ] > > Even that could be more clearly done with > > @paths = [[]] > >> Are you saying that even though @paths is created as an empty array, it >> expects the first element it gets to be an array? If not it will throw >> an error? >> Sorry, I can't check this in irb ATM. > > No, there is no such error checking done. There is also not a default > value as with a Hash - an Array always returns nil when non existing > elements are referenced. > > Maybe the code was created and then modified several times leaving this > artifact. The shortest and also cleanest solution would probably be to > just do > > @paths = [] Thanks Robert, I checked this in irb when I got the chance and you're right. There's no error checking. I can put what ever I like in @paths = Array.new(0,Array.new(0)) just as I can @paths = [] so I'll chalk it up as a artifact as you suggested above. > > Kind regards > > robert cheers, -- Mark