Created
April 30, 2009 16:25
-
-
Save mudge/104527 to your computer and use it in GitHub Desktop.
Convenience method for removing patterns from strings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
# "Hello says Bob" - "Bob" | |
#=> "Hello says " | |
# "Hello says Bob" - /l+/ | |
#=> "Heo says Bob" | |
# | |
# @param [String, Regexp] pattern either a string or regular expression to remove from the string. | |
# @return [String] a copy of the string with the pattern remvoed | |
def -(pattern) | |
gsub(pattern, "") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment