-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday 31 May 2001  5:08pm, Al Chou wrote:
> --- Guillaume Cottenceau <gc / mandrakesoft.com> wrote:
> > [...]
> >
> > > (And I didn't find a way to insert an element in a Array)
> >
> > Ok, sorry for being so dumb, I can insert anything at given
> > position by doing:
> >
> > ary[pos, 0] = ...
> >
> >
> > (or ary[pos..pos-1] but it's not really nice looking)
>
> Thanks, all,
>
> Like Guillaume, I wasn't able to find a way to "insert" an element,
> which is (along with delete, whose implementation is built in to
> Array) the crux of what I wanted a linked list for -- not for
> performance reasons, but because I'm trying to make it easy to
> rearrange the order of the elements in the list.  I was still sitting
> on the fence as to whether I should implement "insert" using
> dissection and recombining of Arrays or continue trying to fix my
> DoublyLinkedList class when I finally checked email again and found
> your solutions.
>
> I wonder if a user-contributed LinkedList subclass of Array would be
> of interest to anyone.

Actually, maybe it's just because I'm using the CVS version, but the 
following program already works for me in Ruby:

test = [1, 2, 3, 4, 5]
test.insert(1, 'test');
p test


Array.insert certainly isn't documented in the reference at 
rubycentral.com, however. If this is a new feature, you can always just 
add it to the old versions yourself. It's certainly not a subclass or 
anything, but the following might be good enough if you want just to be 
hidden from the unwieldy syntax:

class Array
  def insert(pos, data)
     self[pos,0] = data;
  end
end

You can now do Array.insert(pos, data) to insert 'data' at 'pos'. =)

- -- 
Wesley J. Landaker - wjl / mindless.com
http://www.landaker.net            PGP DSS/DH Key: 0x0F338E07
PGPKey FP: 3AAA 424B B488 198E B68B  C0E5 390A BACA 0F33 8E07
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: All your base are belong to us.

iEYEARECAAYFAjsW3DAACgkQOQq6yg8zjgfgtACglwa6+Ed8VvC+K33nxlcMNnUi
qskAoIo2LODE+XACiiyUwduDEFYnSEQt
=Fs0w
-----END PGP SIGNATURE-----