I have a string, e.g.
string = 'foo-bar'
and I want a new string which doesn't contain the character at index 3 (the - in the example string), so the results would be "foobar". The former string must not be changed.
This is what I have so far:
new_string = string.dup
new_string.slice!(3)
new_string
#=> "foobar"
string
#=> "foo-bar"
or as a "one-liner":
new_string = string.dup.tap { |s| s.slice!(3) }
#=> "foobar"
But having to dup and maybe tap looks quite cumbersome. Is there a more concise way?
dupaccepting atap-like block. Not sure if that's a good idea though.