6/6 Multiple redacts using commas?



After reading lots of posts on the forum, I've tried to optimize my code and this works best so far. However, when multiple words are keyed in with commas in between, such as:

Only the first word is redacted, in this case, "like":

Below is my code:

puts "Say something?"
text = gets.chomp

puts "Which words shall I hide? Separate each with a comma."
redact = gets.chomp

words = text.split(" ")
redacted_words = redact.split("," || ", ")

words.each do |word|

    if redacted_words.include? word
        print "REDACTED " 
        print word + " "

I look forward to all your help. Thank you! :smile:



If you want to replace a string consisting of multiple words
you will end up, using

text="This is this is a test text this"
the_str = "this is"
new_contents = text.gsub(/#{the_str}/, "replacement string")