Last active
June 7, 2019 06:24
-
-
Save havenwood/13d0edd9d3d6e0fca60a2761228c27e2 to your computer and use it in GitHub Desktop.
A solution to comet23's problem from #ruby irc
This file contains 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
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