I have to store several lines from .txt files which are located in different directories into variable but I don't know how.
This is my code for printing every line from those .txt files and it works fine, but I don't know how to store them into one variable.
Dir.chdir "/path/to/dir"
Dir.glob("**/*.{mo,txt}").each do |filename|
File.open(filename, "r") do |f|
f.each_line do |line|
puts line
end
end
end
I'm beginner in ruby so please help!!