On Thu, May 26, 2011 at 9:22 PM, Ill E. [email protected] wrote:
#or if i
#a bug or a reason for this behavior? i used the installer. on xp and
on #windows 7
Posted via http://www.ruby-forum.com/.
It’s intentional, because “.” is relative. So your script would work if
invoke it from the same dir on 1.9.1, but would break if you invoke it
the parent dir, because now it is looking in the parent dir for “user”
rather than the dir of the file. So most code that does require
like that has a bug there.
IDK what everyone else does, but for me, if its a bigger project, I add
project root dir to the load path so that require(“user”) would then
user.rb is in the root dir of the project.
For smaller projects, like 1 or 2 files, I just do
In library code (ie a gem you are writing), I don’t think you are
to alter the load path as part of the lib at all, rather do that in your
test code or in your binary, or just rely on rubygems to do it for you.
within the library, you can require things relative to the lib directory
your project, even though the lib itself doesn’t alter the path.
I’d be interested to know whether everyone else does it like this also,
if you guys have discovered some useful pattern I don’t know about.