I have a String str = "abcdefghij", and I want to set str2 to str minus the 4th to 6th character (assuming 0 based index).
Is it possible to do this in one go? slice! seems to do it, but it requires atleast 3 statements (duplicating, slicing, and then using the string).
I went ahead with using the following:
It turned out to be faster and cleaner than the other solutions presented. Here’s a mini benchmark.
Output on Ruby 1.9.2
Edit: Update for
<<.Script:
Output on Ruby 1.9.2