From: David Alan Black Date: 2002-04-16T04:10:07+09:00 Subject: Re: Pascal to Ruby Hello -- On Tue, 16 Apr 2002, Chris wrote: > In article <46487A0D3619D511BF860000F6B99827D2C1CA@PRESGGS17>, > "Firestone, Mark - Technical Support" > wrote: > > > Well, ya... I have a bunch of text, in (in pascal terms) an array of string. > > > > I want to be able to insert somewhere so... > > Something like this perchance? > > class String > def insert ( position, insert_string ) > "#{self[0...position]}#{insert_string}#{self[position+1..-1]}" > end > end > > "foo".insert 1, "bar" # "fbaroo" I was trying something along similar lines with Array. I don't know if it's useful but I really like all the verbs in it: class Array def insert(e,i) m,n = self[0..i-1], self[i..-1] replace m push e concat n return self end end :-) See also the earlier discussions of the pros and cons of a Perl-like "splice" method in Ruby. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav