gwp5008
07-23-2011, 06:29 AM
Hi, I'm in the process of learning Ruby. I've bought a book called Beginning Ruby by Peter Cooper since I am new to programming and wanted to get my feet wet. I've gotten about a sixth of the way through the book and am now attempting to work out some tutorials. The first tutorial involves creating a dummy text file so that I can import it into my IDE (komodo), and then create a text analyzing program for it. So I followed the instructions, created the dummy file, and saved it to where I was instructed to; the same folder where I put this example program (example1.rb). Now the text tells me to put
File.open("text.txt").each { |line| puts line }
in a new ruby file(analyzer.rb) I made in my source code editor. The book said that if "text.txt" is in the current directory I should, "see the entire text file flying up the screen". Instead, I got some weird error that goes:
C:/Users/will/Desktop/Ruby 1.9.2-p180/ruby_work/analyzer.rb:1:in `initialize': No such file or directory - text.txt (Errno::ENOENT)
from C:/Users/will/Desktop/Ruby 1.9.2-p180/ruby_work/analyzer.rb:1:in `open'
from C:/Users/will/Desktop/Ruby 1.9.2-p180/ruby_work/analyzer.rb:1:in `<main>'
After searching online for a bit I found out that I needed to change my current working directory from "C:/Program Files/ActiveState Komodo Edit 6" to where text.txt is-"C:\Users\will\Desktop\Ruby 1.9.2-p180\ruby_work". When I did this the command output gave me:
C:/Users/will/Desktop/Ruby 1.9.2-p180/ruby_work/analyzer.rb:1: syntax error, unexpected $undefined
Dir.chdir(C:\Users\will\Desktop\Ruby 1.9.2-p180\ruby_work)
All the books and resources that I have available to me give a very cursory introduction to the Dir.chdir feature, but don't show how to use it in much of a practical context. I'm sure I must be doing it wrong. Any suggestions would be greatly appreciated. Thanks
File.open("text.txt").each { |line| puts line }
in a new ruby file(analyzer.rb) I made in my source code editor. The book said that if "text.txt" is in the current directory I should, "see the entire text file flying up the screen". Instead, I got some weird error that goes:
C:/Users/will/Desktop/Ruby 1.9.2-p180/ruby_work/analyzer.rb:1:in `initialize': No such file or directory - text.txt (Errno::ENOENT)
from C:/Users/will/Desktop/Ruby 1.9.2-p180/ruby_work/analyzer.rb:1:in `open'
from C:/Users/will/Desktop/Ruby 1.9.2-p180/ruby_work/analyzer.rb:1:in `<main>'
After searching online for a bit I found out that I needed to change my current working directory from "C:/Program Files/ActiveState Komodo Edit 6" to where text.txt is-"C:\Users\will\Desktop\Ruby 1.9.2-p180\ruby_work". When I did this the command output gave me:
C:/Users/will/Desktop/Ruby 1.9.2-p180/ruby_work/analyzer.rb:1: syntax error, unexpected $undefined
Dir.chdir(C:\Users\will\Desktop\Ruby 1.9.2-p180\ruby_work)
All the books and resources that I have available to me give a very cursory introduction to the Dir.chdir feature, but don't show how to use it in much of a practical context. I'm sure I must be doing it wrong. Any suggestions would be greatly appreciated. Thanks