I started learning Ruby a few days ago, so I'm pretty new.
I installed Ruby 1.9.2 on my Win 7 machine. Created a simple analyzer.rb file. It has this one line:
File.open("text.txt").each {|line| puts line}
When I run the code, it gives me this error:
analyzer.rb:1:in `initialize': No such file or directory - text.txt (Errno::ENOENT)
from analyzer.rb:1:in `open'
from analyzer.rb:1:in `<main>'
>Exit code: 1
I don't get it. There is a text.txt file in the same directory as the analyzer.rb file. I also tried feeling the absolute path of the file, C:\Ruby192\text.txt but no dice. What am I missing?
I don't know any Ruby, but Googling the problem reveals that you want File.new, not File.open. File.open looks like it's only part of the operation you want to perform (opening a numeric file descriptor returned from another function).
It sounds a bit counterintuitive as if you're creating a new file, but what you're actually doing is creating a new File object to do stuff with, with the file name as an argument.
Posts
Reference: http://www.ruby-doc.org/core/classes/File.html#M000070
It sounds a bit counterintuitive as if you're creating a new file, but what you're actually doing is creating a new File object to do stuff with, with the file name as an argument.