Baffled on Control Flow Know-How - please check my code


#1

I've done a lot of searching in the forums and can't figure out why this isn't working (error code below):

puts "Enter text: "
text = gets.chomp

puts "What word should I filter out?"
redact = gets.chomp

words = text.split (" ")

words.each do |x|
if x == redact
print "REDACTED "
else print x ""
end
end

ERROR: undefined method `x' for # Context:0xf299dc

Guessing this is a "facepalm-should-have-seen-that" moment. Thanks for the help.


#2

change this to

else print "#{x}" ""

Hope that helps :sunny:


#3

Thank you! That worked with one minor tweak: the quotes after "#{x}" need a space in them, like so:

else print "#{x}" " "

Thank you!