1.9.2 why does relative_require need an additional backtrack in path

Why does Ruby-1.9.2-p0 require an additional ../ for relative paths
when compared to the same code for ruby1.8?

if RUBY_VERSION < '1.9'
  require File.dirname(__FILE__) + library
else
  require_relative File.dirname(__FILE__) + '/..' + library
end

You’re passing an absolute path to require_relative. You can do require_relative library.

That said, in my opinion, require_relative is a misfeature. You should always put the appropriate paths on the load path, and require things relative to it. If your library is called “zoom”, you should do require “zoom/library_name”, not require File.dirname(FILE) + “library_name” from the zoom directory.

Yehuda Katz
Architect | Engine Yard
(ph) 718.877.1325

You're passing an absolute path to require_relative. You can do
require_relative library.

The path that gets sent to relative_root has this value:

bin/../../lib/forex/hll_forex_ca_feed

That does not appear to me to be an absolute path.

That said, in my opinion, require_relative is a misfeature. You should
always put the appropriate paths on the load path, and require things
relative to it. If your library is called "zoom", you should do require
"zoom/library_name", not require File.dirname(__FILE__) + "library_name"
from the zoom directory.

I would very much prefer that Ruby-1.9.2 retained the cwd (.) in the
load path and then all of this jiggery-pokery with require_relative
would not be necessary at all.

However that may be. When I run this code in 1.8.7 under Rails-2.3.8
the script runs without error and produces the expected output. With
1.9.2 and Rails-2.3.8 it also runs without error, albeit requires the
additional ../. I just do not understand why the additional ../ is
required for 1.9.2 require_relative.

Taking your hint I ended up with this construct, which appears to
serve both 1.8 and 1.9 rubies.

require File.expand_path(File.dirname(__FILE__) + library)