From: Mathieu Bouchard Date: 2002-01-28T14:16:57+09:00 Subject: Re: Array#splice method On Mon, 28 Jan 2002, michael libby wrote: > I was a bit surprised to find no splice command in Ruby, but I needed > one for the sandwich example at the end of chapter two, so I wrote > one. I checked past ruby-talk for others, but found only sparse > references to splice. The closest Ruby equivalent to Perl's splice(\@a,$i,$n,$v) function is Array#[i,n]=v; the big difference is the return value. It can be implemented like this: class Array def splice(i,n,v) r = self[i,n] self[i,n]=v r end end Or like this: class Array def splice(i,n,v) r = slice!(i,n) self[i,0]=v r end end ________________________________________________________________ Mathieu Bouchard http://hostname.2y.net/~matju