1. Why do we use word + " "?


#1

Why do we put (" ") after .split and why do we have to put print word + " "?

puts "Text to search through: "
text = gets.chomp
puts "Word to redact: "
redact = gets.chomp

words = text.split(" ")

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


#2

Because we are printing directly inside the loop we need to add white space to separate words.


#4

The " " after text.split tells Ruby what to use as a parameter to determine where to split text (in this case read it as - Every time you come across " " a new word starts).

For the second part of your question, as @mtf said, you need to add a space between words (so you do not end up with "word1word2" but "word1 word2" instead.


#5