Project

General

Profile

Actions

Bug #3799

closed

Unexpected behaviour of require_relative

Added by byrnejb (James Byrne) over 14 years ago. Updated over 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
1.9.2-p0
Backport:
[ruby-core:32108]

Description

=begin
I have this code written to handle ruby 1.8 and 1.9.2:

#!/usr/bin/env ruby

 library = '/../lib/forex/hll_forex_ca_feed'
 
 if RUBY_VERSION < '1.9.2'
   require File.dirname(__FILE__) + library
 else
   require_relative File.dirname(__FILE__) + '/..' + library
 end
 
 HLLForexCAFeed::Main.new(ARGV).execute
 

This code works with 1.8.6+ and 1.9.2. However, please note the insertion of an additional directory reverse traversal. If I do not provide this to Ruby-1.9.2 then the require fails with this error:

 $ bin/forex
 bin/forex:8:in `require_relative': no such file to load -- /home/byrnejb/Software/Development/Projects/proforma.git/bin/lib/forex/hll_forex_ca_feed (LoadError)
         from bin/forex:8:in `
 

My question is: Why does Ruby-1.9.2-p0 require the additional backtrack?
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0