Skip to content

Instantly share code, notes, and snippets.

@mudge
Created April 30, 2009 16:25
Show Gist options
  • Save mudge/104527 to your computer and use it in GitHub Desktop.
Save mudge/104527 to your computer and use it in GitHub Desktop.
Convenience method for removing patterns from strings.
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