As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread:

Getting an error with the simplest Ruby program

PerpetualPerpetual Registered User regular
edited July 2011 in Help / Advice Forum
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:"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?

Perpetual on


  • Options
    PaleCommanderPaleCommander Registered User regular
    edited July 2011
    I don't know any Ruby, but Googling the problem reveals that you want, not looks like it's only part of the operation you want to perform (opening a numeric file descriptor returned from another function).


    PaleCommander on
  • Options
    EchoEcho ski-bap ba-dapModerator mod
    edited July 2011
    What he said - is what you want.

    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.

    Echo on
Sign In or Register to comment.