I'm pretty much entirely new to programming, so bear with me. I am on a Macbook Pro running 10.6.6.
At the beginning of the "Learn to Program" tutorial are these directions:
Save your program (yes, that's a program!) as calc.rb (the .rb is what we usually put at the end of programs written in Ruby). Now run your program by typing ruby calc.rb into your command line. It should have put a 3 on your screen. See, programming isn't so hard, now is it?
When I type ruby calc.rb
I get the following error:
ruby: No such file or di开发者_运维技巧rectory -- calc.rb (LoadError)
What am I doing wrong? "Calc.rb" is saved on my desktop, if it matters.
If you have named your file "Calc.rb" you'll need to run ruby Calc.rb
(capital "C").
Also make sure that you're navigating the /Desktop
directory — e.g. type
cd ~/Desktop
ruby Calc.rb
You can use ls
to get a list of all the files in the current directory. You could use that to see if the file you're trying to execute actually exists.
In Terminal, did you change your current directory to your desktop before running your program ?
If your program is stored on your desktop, you first need to change directory to your desktop or your Ruby script will not be found.
$ cd Desktop
$ ruby calc.rb
ruby 1.9.3p0 (2011-10-30) [i386-mingw32]
C:\Ruby Programs>ruby calc.rb
ruby: No such file or directory -- calc.rb (LoadError)
C:\Ruby Programs>ruby calc.rb.txt
3
One should not have to add the .txt extension while attempting to run the program from whithin the program's home folder. I have to though.
Did you call your file Calc.rb and saved it as a rb file to. becouse then its called internaly. Calc.rb.rb
and be sure to run cmd from desktop :D
You need to make sure you're running the command in the same directory you have the calc.rb file.
Type "cd " then the directory calc.rb is in to change it.
Then just do "ruby calc.rb"
精彩评论