From: "W. Kent Starr" Date: 2001-05-02T00:38:31+09:00 Subject: [ruby-talk:14491] Re: RCR: Array#insert On Tuesday 01 May 2001 03:24, Yukihiro Matsumoto wrote: > Hi, > > In message "[ruby-talk:14479] Re: RCR: Array#insert" > > on 01/05/01, Shugo Maeda writes: > |At Sat, 28 Apr 2001 19:35:25 +0900, > | > |Marko Schulz wrote: > |> I would actually prefer an version that is able to insert more than > |> one element, just like push can add more than one element at the > |> end. So here is my take: > |> > |> > |> class Array > |> def insert(pos, *elem) > |> self[pos,0] = elem > |> self > |> end > |> end > | > |I agree. > > Sounds good. It will be merged into the development branch. > > matz. FWIW this also works with String, trival but useful :-) # extend String class class String def insert (pos, txt) self[pos,0] = txt self end end # test it x = "Hello World" puts x x.insert 6, "my " puts x # end And the output: irb(main):047:0> "Hello World" irb(main):051:0> Hello World nil irb(main):052:0> "Hello my World" irb(main):053:0> Hello my World nil irb(main):054:0> Regards, Kent Starr elderburn@mindspring.com