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 text.downcase! puts "Which words shall I hide? Separate each with a comma." redact = gets.chomp redact.downcase! words = text.split(" ") redacted_words = redact.split("," || ", ") words.each do |word| if redacted_words.include? word print "REDACTED " else print word + " " end end
I look forward to all your help. Thank you!