Remove substring from the string

ruby, string

Solution

You can use the slice method:

a = "foobar"
a.slice! "foo"
=> "foo"
a
=> "bar"

there is a non '!' version as well. More info can be seen in the documentation about other versions as well: http://www.ruby-doc.org/core/classes/String.html#method-i-slice-21

Problem

I am just wondering if there is any method to remove string from another string? Something like this: ``` class String def remove(s) self[s.length, self.length - s.length] end end ```

Original source