Issue with require and require_relative with symlinked directories
Symlinked directories cause an issue with require_relative where libraries loaded from a symlinked path (e.g. in a typical Capistrano / Bundler deployment) can be double-loaded.
- Clone git repo from https://github.com/fidothe/symlink-require
$ ruby use-symlink.rb
Expected result: No warning from double-loading of constants issued.
Actual result: double-loading of file causing already-initialised constant warning.
In the example I linked above,
require_relative to load
When the example also requires
dependent.rb the file is double-loaded and we see a warning about already-initialized constant.
The problem is that when
use-symlink.rb (line 7) checks the set of loaded files it uses an absolute path containing the symlink (since that is what was added to $LOAD_PATH), but when
require_relative in target.rb is called, it uses an absolute path containing target of the symlink, causing the double-load.
Is this discrepancy intended behaviour on Ruby's part?