Where should I put words.list? I tried writing out a path to it, but I
keep getting “No such file or directory - words.list”.
words.list should be in the same directory as the .rb that’s calling
it. If that doesn’t work and using the absolute path doesn’t work try
a relative path like …/…/words.list if it’s in your rails_root. In
addition the following code might change things or not, I doubt it
will make it work but it’s a little prettier.
Try the following code:
File.open(“words.list”).each do |line|
Do something with the var line
end
or a slightly different approach
words = File.readlines(“words.list”)
I’m not sure why but IO and foreach seem to be pretty rarely used. I
think they’ve gone out of style. Maybe just because File is easier to
get the gist of when dealing with Files and IO when doing io streams
like tcp/ip.
Hope that helps. If you don’t already have it in your bookmarks try to
find _why’s Pickaxe on google; it’s an old copy of the Ruby manual
with links to the sections. Got me through a lot of pain
Sincerely,
Chuck V.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.