From: Robert Klemme Date: 2007-06-04T21:20:34+09:00 Subject: Re: No way of looking for a regrexp match starting from a particular point in a string? On 04.06.2007 14:06, Robert Dober wrote: > On 6/4/07, Robert Klemme wrote: >> On 04.06.2007 13:28, Robert Dober wrote: > >> Robert, actually string[n..-1] is cheaper than you might assume: I >> believe the new string shares the char buffer with the old string, so >> you basically just get a new String object with a different offset - the >> large bit (the char data) is not copied. > I am afraid that this is not true anymore when the slice is passed as > a formal parameter, the data has to be copied :( > > irb(main):011:0> def change(x) > irb(main):012:1> x << "changed" > irb(main):013:1> end > => nil > irb(main):014:0> a="abcdef" > => "abcdef" > irb(main):015:0> change(a[1..2]) > => "bcchanged" > irb(main):016:0> a > => "abcdef" Copying in this case is not caused by using the string as a parameter but by appending to it. I thought this thread was about /scanning/ which is a read only operation. Did I miss something? Kind regards robert