From: Martin DeMello Date: 2003-02-13T21:48:40+09:00 Subject: Re: Should substrings be modifiable in-place?? Chris Pine wrote: > Why not just str.reverse!(x,y) or str.reverse!(x..y) or something? We could > do this for reverse (no `!'), too, and probably lots of other String > methods, to suggest 'only operate on substring'. class String instance_methods.select {|i| i =~ /!$/}.each {|m| module_eval <<-here def s#{m}(*args) a = args.shift if (Range === a) a, b = a.first, a.last else b = args.shift end c = self[a,b] self[a,b] = c.send(:#{m},*args) end here } end a = "hello world" a.sreverse!(3,7) p a #==> "hellrow old" a.sgsub!(0,5,/l/,'p') p a #==> "hepprow old"