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:

See also:

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’

Leave a Reply

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