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 #1

Updated by nobu (Nobuyoshi Nakada) over 14 years ago

=begin
Hi,

At Wed, 8 Sep 2010 01:59:01 +0900,
James Byrne wrote in [ruby-core:32108]:

$ 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?

Is this the real code?

library = '../lib/forex/hll_forex_ca_feed'
require_relative library

I can't reproduce the error with the above.

--
Nobu Nakada

=end

Actions #2

Updated by nobu (Nobuyoshi Nakada) over 14 years ago

  • Category set to core
  • Status changed from Open to Feedback
  • ruby -v set to 1.9.2-p0

=begin

=end

Actions #3

Updated by naruse (Yui NARUSE) almost 14 years ago

  • Status changed from Feedback to Rejected

=begin
No feedback.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0