I have an array of strings, and I want to search for specific words (cat or dog) in each row of the array and be able to view the results in the order in which they were.
Examples of offers
Strings[0] = "Subject family leans toward cats"
Strings[1] = "Test subject prefers dogs"
I tried String.each {|x| x.scan(/cat|dog)/ }, but I would only get the last result in the results. how can i do it right to get puts $1 => cat puts $2 => dog? Thank you for your help.
source
share