Hi I’m going through this loop and sending a list of words lines and a string str to match it. For some reason it’s not printing eureka though:
def search_array(str, lines)
count = 0
lines.each do |i|
count +=1
if str == i
puts 'eureka'
end
end
end
FILE_LOC = "words.txt"
lines = File.readlines(FILE_LOC)
word = "hello"
search_array(word, lines)
This works for me:
I’m not sure how you are running your program, but you can just copy and paste this into a text editor and save it as “LooperTest.rb”. Then open your terminal and change directories to the path with this file in it and run it like this:
ruby LooperTest.rb