After smashing my head against the screen for awhile I finally got this working after looking through a post in ~Oct '15. Problem is I don’t know why this works and my original one doesn’t.
puts "Please provide the text to search: " text = gets.chomp puts "Please type the 3 words you'd like redacted: " word_a = gets.chomp word_b = gets.chomp word_c = gets.chomp redact = [word_a, word_b, word_c] words = text.split(" ") words.each do |word| if redact.include?(word) print "REDACTED " else print word + " " end end
my if statement of
doesn’t work. Looking at it, the second makes more sense because it’s scanning the all the text (converted into individual strings held in an array) for any strings that match the array of strings in
redact. When used I get an error that says cannot covert Array into String.
The one that works, scans
redact instead of
word. I feel you should be checking the smaller list against the bigger list rather than the other way around.
Does it work because
words.each do |word| sets the parent method the others are encased in? Does it have to do with how they were made; redact being assigned as variables in the array vs being converted from 1 string? Is it because I’m searching each individual
words to see if they’re included on the
Any help would be appreciated.
Link that helped me solve it in the first place.