Ruby: require and require_relative; and why does Ruby remove “.” from the LOAD_PATH

require_relative lets you load a file relative to the file containing the require_relative statement.

The docs:

http://extensions.rubyforge.org/rdoc/classes/Kernel.html

See also:

http://stackoverflow.com/questions/3672586/what-is-require-relative-in-ruby

Ruby removes . from the LOAD_PATH for security reasons.

You can get around it by: 

1. using absolute paths

File.expand_path(__FILE__) etc…

2. using ./, e.g.

require ‘./filename’

3. or require_relative

require_relative ‘filename’

http://stackoverflow.com/questions/2900370/why-does-ruby-1-9-2-remove-from-load-path-and-whats-the-alternative?lq=1

Leave a Reply

Your email address will not be published. Required fields are marked *