Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby require 'file' doesn't work but require './file' does. Why?

Tags:

ruby

require

I have a folder full of ruby files, and when I try and require one file in another that is in the same directory using require 'file' I get a LoadError but when I use require './file' everything works fine. Can somebody explain to me why this happens and if there is any way I can require a file without adding a ./ onto the file?

(Picture of directory): alt text

like image 948
ab217 Avatar asked Sep 25 '10 20:09

ab217


1 Answers

If you want to require a file not from the system $LOAD_PATH but rather relative to the directory of the file you are requireing from, you should use require_relative. (Which, as you can see, isn't exactly extensively documented.)

like image 190
Jörg W Mittag Avatar answered Oct 28 '22 08:10

Jörg W Mittag