From: dblack@... Date: 2006-03-28T22:23:07+09:00 Subject: Re: Array resizing Hi -- On Tue, 28 Mar 2006, Victor Shepelev wrote: > Pierre wrote > >> So you may code yourself your resize : >> >> class Array >> def resize(new_size, value=nil) >> if new_size < length >> slice!(new_size, length) >> else >> fill(value, -1, new_size-length) >> end >> self >> end >> end > > Yes, I can (in fact, I already did). > > The question is more ideological than technical. Why not to have > Array#resize in standard library? It seems not very rational. I think it might be because the size of an array isn't important if the array just contains nils, because uninitialized values default to nil anyway. And if you're adding non-nil elements to the array, then the fact that the size changes is not really the main point; it's just a side-effect of the operation, so referring to it as a "resize" operation doesn't fit very well. David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black