I'm going through a file line by line and I want to check if that line contains any element from an array. for instance if I have:
myArray = ["cat", "dog", "fish"]
and the current line said:
I love my pet dog
The output would say
Found a line containing array string
Here's what I have but it doesn't work.
myArray = ["cat", "dog", "fish"]
File.open('file.txt').each_line { |line|
puts "Found a line containing array string" if line =~ myArray #need to fix this logic
}
I've tried include?
and any?
but don't know if I'm using them right.
UPDATE:: An important part i left out. I need exact matches! so i don't want the statement to return true if it isn't exact. For instance- if my line says "I love my pet doggie" this statement should return false since "dog" is in the array. Not "Doggie"
My mistake on the poor clarification