I run testrequire in Command Prompt, I get:
<internal:lib/rubygems/custom_require>:29:in `require': no such file to
load -- string_extensions (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from O:/Ruby/Practice/testrequire.rb:1:in `<main>'
Sam Rose wrote in post #1030126:
If you're not on 1.9.2 and don't have require_relative, I believe this
require './string_extensions'
The problem with doing something like this is that the requiring file
will only find the required file when the program's invoked from that
directory. For example, if you move back one directory and then try to
run it, it won't work.
It's a good idea to make scripts as portable as possible, so something
like this would be a good idea, I think.
What this means:
__FILE__ is a string of the current filename
File.dirname(f) gets the directory of f
File.expand_path(f) expands things like "~" and "."
File.join(*files) joins all the files with whatever file separating
character is appropriate on your system. Ex: '/', '\'
As much as this might seem like overkill, it might be a good habit
to get into because LoadErrors are annoying as hell.
You will see that the 2nd command lists your current directory as one of its load paths.
-Jingjing
···
-----Original Message-----
From: Kaye Ng [mailto:sbstn26@yahoo.com]
Sent: Saturday, November 05, 2011 12:23 AM
To: ruby-talk ML
Subject: Re: 'require' problem
Ryan Davis wrote in post #1030259:
ruby -I. your_script.rb
Thanks Ryan, but like I said, I would like to use just *require
'my_script'*