...

Need help getting tutorial started

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

dotnetmind
08-18-2011, 08:01 PM
Try to start here:

One of the best free Ruby books online Programming Ruby (http://www.ruby-doc.org/docs/ProgrammingRuby/)

Why's Poignant Guide (http://mislav.uniqpath.com/poignant-guide/) To Ruby is pretty educational.

CrazyCrisUk
11-03-2011, 12:04 PM
All I can see is that the errors suggest you keep flicking between using forward slashes and back slashes in your addresses.

Are you on windows or linux?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum