Search code examples
rubyrakerequireload-path

Why does Ruby 1.9.2 remove "." from LOAD_PATH, and what's the alternative?


The latest changesets to Ruby 1.9.2 no longer make the current directory . part of your LOAD_PATH. I have a non-trivial number of Rakefiles that assume that . is part of the LOAD_PATH, so this broke them (they reported "no such file to load" for all require statements that based off the project path). Was there a particular justification for doing this?

As for a fix, adding $: << "." everywhere works, but seems incredibly hacky and I don't want to do that. What's the preferred way to make my Rakefiles 1.9.2+ compatible?


Solution

  • It was deemed a "security" risk.

    You can get around it by using absolute paths

    File.expand_path(__FILE__) et al
    

    or doing

    require './filename' (ironically).
    

    or by using

    require_relative 'filename'
    

    or adding an "include" directory

    ruby -I . ...
    

    or the same, using irb;

    $irb -I .