Don't understand Redact Logic


#1

I'm having trouble understanding the logic of this code and what kind of input/output I should be expecting.

puts "Text to search through: " #what type of input is supposed to go here?
text = gets.chomp
puts "Word to redact: " #what type of input is supposed to go here?
redact = gets.chomp

words = text.split(" ")

words.each do |word| #
if word != redact
print word + " "
else
print "REDACTED "
end
end


#2

The goal is to provide a text (one or more words separated by spaces), and a word to "redact". The program will then search through the text for occurrences of this word and "replace" them by REDACTED.


#3

Thank you so much for your response! For some reason when I initially typed in the input, the word I wanted to redact, still kept showing up. I typed it again just now and it shows "REDACTED". That's why I was really confused as to what type of output I was supposed to be getting.