How can I load my own files to ruby? (Win XP)

S

Stephan.Kassel

I am just trying to get some knowledge in Ruby. For this I am playing
with some tutorials.

In the tutorial I have to save some code to a file and load it
afterwards in the irb (with require).

I don't want to mess up the installation, so I am saving all files
under my own special directory E:/User/stk/Programming/Ruby.

Which enviroment variable do I have to use? What shall I do?

There are no comments on this in the installation instructions and in
the faq(s) afaik.

Any help is appreciated. (No, I don't want to make a lot of other
installations to get it done.)
Stephan.

P.S.: I have installed ruby 1.8.2 with the OneClickInstaller on
RubyForge.
 
R

Ross Bamford

I am just trying to get some knowledge in Ruby. For this I am playing
with some tutorials.

In the tutorial I have to save some code to a file and load it
afterwards in the irb (with require).

I don't want to mess up the installation, so I am saving all files
under my own special directory E:/User/stk/Programming/Ruby.

Which enviroment variable do I have to use? What shall I do?

(I don't know about Windows, but I expect it's the same in this regard?).

If you start IRB from that directory, you should be able to require your
file with a simple:

require 'myfile'

assuming your file is named 'myfile.rb'. You can also give full
path/filename to require I think.

Alternatively, a quick and dirty way in IRB is to just do:

$: << 'E:/User/stk/Programming/Ruby' # ?slashes?

when you first run IRB. From then, your directory will be in the library
search path.

(Aside: Stick with it - IRB will quickly become one of the most valuable
tools you have when learning Ruby :))
 
K

Kevin Brown

In the tutorial I have to save some code to a file and load it
afterwards in the irb (with require).

I don't want to mess up the installation, so I am saving all files
under my own special directory E:/User/stk/Programming/Ruby.

e:
cd User\stk\Programming\Ruby
irb -r yourfile.rb or irb then requre 'yourfile.rb'

Am I missing something?
 
B

Bob Showalter

I am just trying to get some knowledge in Ruby. For this I am playing
with some tutorials.

In the tutorial I have to save some code to a file and load it
afterwards in the irb (with require).

I don't want to mess up the installation, so I am saving all files
under my own special directory E:/User/stk/Programming/Ruby.

Which enviroment variable do I have to use? What shall I do?

The RUBYLIB environment variable lets you specify additional directories
to be searched by 'require'. irb picks this up. Both ruby and irb (at
least as of 1.8.2) support a -I option too.
 
S

Stephan.Kassel

Thank you.

This was the answer I really needed. Also many thanks to Ross to
provide me with a quick workaround. My problem is solved. (Maybe until
the next time when I need to know something about useful environment
variables for ruby ;-)

Regards,
Stephan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,197
Messages
2,571,041
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top