I'm trying to iterate through an array of strings and replace the words if they match any of the substitution rules:
array= ["I love chicken!", "I love lamb!", "I love beef!"]
substitutions = {
"love" => "hate",
"lamb" => "turkey"
}
I want to iterate through the array and check for any words that match with the keys within the substitutions hash. The array would then become:
array= ["I hate chicken!", "I hate turkey!", "I hate beef!"]
This is what I have so far:
array.each do |strings|
strings = strings.split
strings.each do |word|
substitutions.each do |phrase,substitute|
if word == phrase
word = substitute
return word
end
end
end
end