0

I can't seem to load files. I am using Ruby 2.0.0 x64 and the built in command prompt with Ruby.

I have 2 problems. 1) If I use Powershell or the cmd.exe, I can't access Ruby if I type in irb. Any idea how to connect the two.

2) So instead I use the downloaded command prompt with Ruby. I have a file created called banking.rb. I am trying to load the file so I can test my code. Here is the location of my file:

C:\Users\Jwan\Desktop\Ruby Programs.

When I type in load 'banking.rb', I get this error:

LoadError:  cannot load such file -- banking.rb  
    from <irb>:6:in 'load'
    from <irb>:6
    from C:/Ruby200-x64/bin/irb:12:in '<main>'

So my guess is that the ruby loadpath is incorrect? The folder where this file is located is on my desktop. How do I change my loadpath (full disclosure:, please try to dumb down the instructions. I didn't even know what loadpath was prior to this post)

Jwan622
  • 11,015
  • 21
  • 88
  • 181
  • See also http://stackoverflow.com/questions/2900370/why-does-ruby-1-9-2-remove-from-load-path-and-whats-the-alternative/2900545#2900545 [basically, ruby doesn't load from the current working directory anymore] – rogerdpack Aug 15 '14 at 19:06

1 Answers1

1

Check the Ruby docs for Kernel.load:

Loads and executes the Ruby program in the file filename. If the filename does not resolve to an absolute path, the file is searched for in the library directories listed in $:.

So you can either type the absolute path

load 'C:\Users\Jwan\Desktop\Ruby Programs\banking.rb'

or modify $:

$: << 'C:\Users\Jwan\Desktop\Ruby Programs'
load 'banking.rb'

$: can also be referenced with $LOAD_PATH. It is the array of directories that Ruby searches for files to load. If you want to permanently add directories to your load path, you can set the RUBYLIB environment variable to a colon-separated list of them (look up how to do this on Windows, it's nestled deep in some menu).

Max
  • 21,123
  • 5
  • 49
  • 71
  • It works! But what does $: << do? What does Kernel mean? – Jwan622 Aug 14 '14 at 03:43
  • Also, is there a way for the library directories to always include C:\Users\Jwan\Desktop\Ruby Programs even if I restart teh command prompt? Also can I users backslashes instead of forward slashes in Windows 7? – Jwan622 Aug 14 '14 at 03:53
  • `Kernel` is where all of Ruby's "global functions" (`load`, `puts`, `exit`, etc.) live. See my edited answer for your other question. – Max Aug 15 '14 at 17:42