From: Lyle Johnson Date: 2003-02-13T09:06:36+09:00 Subject: Re: Should substrings be modifiable in-place?? Hal E. Fulton wrote: > I've been thinking about this for > a half hour or so. > > Rather than writing this kind of thing: > > str[x,y] = str[x,y].reverse > str[x..z] = str[x..z].reverse > > I'd like to be able to do this: > > str[x,y].reverse! > str[x..z].reverse! > > There is probably some good reason this > won't work, though. ;) > > Someone care to comment? The current semantics are that this: str[x, y] = ... some string ... modifies str in place, but this: str[x, y] returns a *new* String object (and that's the clincher) which is a slice from 'str'. So if str[x, y] returns a new String, then I would *expect* that str[x, y].reverse! instantiates a new String, then calls String#reverse! to perform an in-place reverse on that new string -- but still leaves the original string (str) unmodified.