Path problems

I am learning Ruby from scratch, using a beginner’s book and have
installed Ruby on my WIN Vista platform. This is my first use of
Ruby-Talk. I hope the following questions/problems are within the scope
of Ruby-Talk:

  1. The book says there should be two source/text editors, FreeRide and
    SciTE, but I only have SciTE.

  2. Using SciTE, F5 or Tools/Go, results in an error message to the
    effect that the system can’t find my source file. The only way I have
    found to run my program is from the command line, and then it only works
    if I use an old DOS path command, include the full path before the
    program name, or change to the directory in which the source file is
    located. Is there a way to set path from within SciTE?

Thanks,
RBA

On Dec 31, 4:14 pm, “Roger B. Atkins” [email protected] wrote:

I am learning Ruby from scratch, using a beginner’s book and have
installed Ruby on my WIN Vista platform. This is my first use of
Ruby-Talk. I hope the following questions/problems are within the scope
Hi Roger,

  1. I’ve not seen Freeride distributed with the stock ruby
    installation.
    if you’d like to use it, it’s here =>
    http://rubyforge.org/frs/?group_id=31

My suggestion starting out would be to use Notepad++

  1. For errors that you get while running, it is best to post the error
    verbatim to get the best help as opposed to describing the error.

$LOAD_PATH or $: can be set from with your program. A handy snippet to
add to the top of your programs is

$:.unshift File.dirname(FILE) unless
$:.include? File.dirname(FILE)

This will add the path of your file to the load path unless
it is already there.

If you want to know what your load path is, open an irb session
and enter p $:

Have fun with Ruby,

Darryl

Thanks Darryl.

The error message:

ruby Test2.rb
The system cannot find the file specified.

I do not understand the code in your handy snippet. I do not recognize
“.unshift” or “FILE”. I am guessing I should substitute something
in place of “FILE”, but so far I have not found the right
substitute. I have tried the complete path name, the file name, the
directory name, and I get the same error message every time.

I guess I will resort to closing the file and reopening it each time
before I run the program, at least until I learn more. Thanks again.

RBA

.

On Dec 31, 9:01 pm, “Roger B. Atkins” [email protected] wrote:

Thanks Darryl.

The error message:

ruby Test2.rb
The system cannot find the file specified.

are you invoking ruby in the directory where “Test2.rb” exist?

Also, is the file named “Test2.rb” and not “test2.rb”, things are case
sensitive sometimes.

On Dec 31, 7:12 pm, Luis L. [email protected] wrote:

Also, is the file named “Test2.rb” and not “test2.rb”, things are case
sensitive sometimes.


Luis L.

Hello again Roger,

Sorry if I threw too much at you…
(FILE) is a ruby keyword that holds the dir & file of the
program that it’s used in.

Copy the below snippet into a file and run it for a better feel.

$:.unshift File.dirname(FILE) unless
$:.include? File.dirname(FILE)

puts “reveal Filename and Dirname attributes \n\n”
a = File.dirname(FILE)
b = File.basename(FILE)
c = (FILE)
d = File.dirname $0
e = $0
f = $PROGRAM_NAME

puts " a - the current directory => #{a}"
puts " b - the current filename => #{b}"
puts " c - the current directory and filename => #{c}"
puts " d - same output as ‘a’ only using $0 => #{d}"
puts " e - same as ‘c’ only using $0 => #{e}"
puts " f - same as ‘c’ only using $PROGRAM_NAME => #{f}"

Regards,
Darryl

On Thu, Dec 31, 2009 at 9:14 PM, Roger B. Atkins
[email protected] wrote:

I am learning Ruby from scratch, using a beginner’s book and have installed
Ruby on my WIN Vista platform. This is my first use of Ruby-Talk. I hope
the following questions/problems are within the scope of Ruby-Talk:

  1. The book says there should be two source/text editors, FreeRide and
    SciTE, but I only have SciTE.

My guess is that you installed using the Ruby one click installer? If
so, I’d suggest uninstalling this, and installing the newer
rubyinstaller which contains Ruby 1.9, and doesn’t try to force SciTE
on you. If I recall correctly, this installer will sort out all your
path problems for you.

http://rubyinstaller.org/download.html


Paul S.
http://www.nomadicfun.co.uk

[email protected]

Thanks Darryl. I used SciTE to put your code in a file named test3.rb
and saved it. I closed the file, opened it again, pressed F5 and:

ruby test3.rb
The system cannot find the file specified.

Then I saved the file to the same directory where ruby is located,
closed it, opened it again in SciTE and it worked:

ruby test3.rb
reveal Filename and Dirname attributes

a - the current directory => .
b - the current filename => test3.rb
c - the current directory and filename => test3.rb
d - same output as ‘a’ only using $0 => .
e - same as ‘c’ only using $0 => test3.rb
f - same as ‘c’ only using $PROGRAM_NAME => test3.rb

Exit code: 0

In between attempts, I did some playing at the command prompt. In the
process I remembered that DOS doesn’t recognize directory names
containing multiple words with spaces between them. Since my earlier
source files are all in a directory named “Ruby Files”, I thought the
directory name might be part of the problem. I changed the directory
name to RubyFiles, but it did not solve the problem.

I notice that now SciTE shows “ruby test3.rb” before the results,
whereas earlier it was just showing the file name without "ruby " in
front of it. Perhaps the active directory changed in SciTE.

Anyway, I will put all my files in the directory with ruby since I can’t
seem to control SciTE.

Thanks again and Happy New Year!

RBA

I am not sure what you mean, but I probably would not know the answer if
I understood the question. I infer that, for the purpose of loading and
saving the file, SciTE is looking at the directory where Test2.rb
exists, because that is the directory listing that appears when I select
Save As from the File menu. Whether or not SciTE invokes ruby in that
directory, where Test2.rb exists, or changes to the directory where ruby
exists, I do not know.

Changing the case of the first letter in the file name made no
difference in the result, which is:

ruby Test2.rb
The system cannot find the file specified.

Thanks,

        RBA

On 01.01.2010 03:25, Roger B. Atkins wrote:

In between attempts, I did some playing at the command prompt. In the
process I remembered that DOS doesn’t recognize directory names
containing multiple words with spaces between them. Since my earlier
source files are all in a directory named “Ruby Files”, I thought the
directory name might be part of the problem. I changed the directory
name to RubyFiles, but it did not solve the problem.

I notice that now SciTE shows “ruby test3.rb” before the results,
whereas earlier it was just showing the file name without "ruby " in
front of it. Perhaps the active directory changed in SciTE.

This looks like SciTE on Windows doesn’t use your PATH variable (by
default, the RubyInstaller, as well as the old Ruby O.-Click installer
put Ruby into your path, os you can use it from anywhere), and instead
some hardcoded paths, or so.

Anyway, I will put all my files in the directory with ruby since I can’t
seem to control SciTE.

I’d stop using SciTE instead, so you can keep your Ruby nice and clean,
and avoid possible problems when upgrading / changing your Ruby
installation.

If you open a command line (Start Orb -> type “cmd” sans quotes and hit
enter), and then type “path”, sans quotes again, can you find Ruby in
there somewhere? If that is the case, you can run Ruby scripts from
anywhere you like (including paths with Spaces, like your “Ruby Files”
directory).
You can’t use SciTE’s comfort, unfortunately (and installing, say,
NetBeans 6.8 with Ruby would be overkill), and instead have to use the
commandline “ruby script.rb”.

For example:
c:\Scripts>ruby gemconfig.rb
sitedir: C:/Ruby/lib/ruby/site_ruby
bindir: C:/Ruby/bin
sitelibdir: C:/Ruby/lib/ruby/site_ruby/1.8
datadir: C:/Ruby/share
vendordir:
EXEEXT: .exe
libdir: C:/Ruby/lib
vendorlibdir:
ruby_install_name: ruby
RUBY_SO_NAME: msvcrt-ruby18
ruby_version: 1.8
arch: i386-mingw32

c:\Scripts>cat gemconfig.rb
require “rubygems”
Gem::ConfigMap.each do |config,value|
puts “#{config}: #{value}”
end
c:\Scripts>path
PATH=C:\Ruby\bin;

Note that “cat” is not available on your Windows install, unless it’s
setup similar to mine.
Also note, that I abbreviated the mess that is my path environment so
that you can easily spot what you should find there.

Phillip,

Ruby was not there. I changed the path setting within Vista through the
control panel. Now SciTE finds ruby, and the F5 command works as
intended. (I had first tried changing PATH from the command line, but
the change did not stick, which is why I continued to have problems.)
Now C:\users\roger\documents\rubyfiles>test3.rb works and
C:\users\roger\documents\rubyfiles>ruby test3.rb works. Path problem
solved! Thanks.

-RBA