Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active June 7, 2019 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/13d0edd9d3d6e0fca60a2761228c27e2 to your computer and use it in GitHub Desktop.
Save havenwood/13d0edd9d3d6e0fca60a2761228c27e2 to your computer and use it in GitHub Desktop.
A solution to comet23's problem from #ruby irc
def censor(sentence, words, redact: 'aeiou', filler: '*')
sentence.gsub /#{Regexp.union(words).source}/i do |word|
word.tr redact, filler
end
end
censor 'Gosh darned it', %w[gosh darn shoot]
#=> "G*sh d*rned it"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment