From: Wilbert Berendsen Date: 2001-04-27T17:44:30+09:00 Subject: [ruby-talk:14308] Re: RCR: Array#insert Today at 12:40pm, Shugo Maeda said: > At Wed, 25 Apr 2001 01:28:36 +0900, > Dave Thomas wrote: > > > Ok, this may be a dumb question, but, is it possible to insert into an > > > array. > > > > > > EG, > > > a = [1, 2] > > > a.insert(1,3) => [1,3,2] > > > > a = [1, 2] # => [1, 2] > > a[1,0] = 3 # => [1, 3, 2] > > Some people asked the same question. Is it a bad idea to provide > Array#insert? > # There is another reason - Array#[]= is not efficient for one > # object insertion. > > Shugo I'm new to ruby, but I think that would be nice, and when you call Array.insert with only one argument it will insert at the beginning (like push does at the end) eg, a = [1, 2, 3] a.insert "hi" # => ["hi", 1, 2, 3] Regards, Wilbert -- /"\ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . /"\ \ / ASCII Ribbon Campaign Wilbert Berendsen \ / X - NO HTML/RTF in e-mail http://www.xs4all.nl/~wbsoft X / \ - NO MSWord docs in e-mail http://linuxathome.nl / \