I have a string, that contains a sentence. Then I have an array, that have some words. I need to check, if that sentence contains words given in the array, or more specifically, even if words from the array are parts of the words in that sentence. Case insensitive. In case there are matches, I need to change the words in that sentence to something else, for ex. "*****". I have tried different options like: any?, include?, gsub, but didn't manage to make it work properly. Would be very grateful for any help!
For example:
array = ['ga', 'day', 'sky']
string = "Peter went to the garden, to gather oranges. It was a sunny day and there were a lot of birds in the sky."
array.each do |word|
if string.include? (word)
temp.gsub(word, "*****") # or temp[word] = "*****"
end
end
Desired output for printing the string would be:
Peter went to the *****, to ***** oranges. It was a sunny ***** and there were a lot of birds in the *****.