Redacting words with period at the end


I want my code to be able to redact words at the end of a sentence if there's a punctuation mark at the end so I added an OR condition.

But what ends up happening is it redacts the entire sentence with "REDACT REDACT REDACT" for every word in the sentence.

I don't get any error messages.

Can someone please help me figure out where I went wrong?

puts "Write something: "
text = gets.chomp.downcase
puts "This is what you want to redact: "
redact = gets.chomp.downcase

words = text.split(" ") 

words.each do |words|
if words == (redact + ".") || redact
    print "REDACTED "
    print words + " "


I think you would take the same code (just words == redact) and add an extra delimiter, so instead of:

words = text.split(" ")

It would be:

words = text.split(/[\s,.]/)

I think that should work.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.