Project

General

Profile

Bug #9244

unexpected behaviour of 'require' when $LOAD_PATH gets changed

Added by sylvain.joyeux (Sylvain Joyeux) over 5 years ago. Updated over 2 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
1.9.3p484, 2.0.0p353, 2.1.2 2.1.6p336 2.2.1p85 2.3.1p112
Backport:
[ruby-core:59069]

Description

For the purpose of reproducing the error, let's assume that I have two folders a and b which both contain a file test.rb

In the following script, b/test.rb will NOT get loaded:

 $LOAD_PATH.unshift File.join(Dir.pwd, 'a')
 require 'test.rb'
 $LOAD_PATH.unshift File.join(Dir.pwd, 'b')
 require 'test.rb'

I would have expected this behaviour before, when required files were not registered through their absolute paths in $LOADED_FEATURES. Right now, I find it confusing.

History

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

  • Description updated (diff)

Updated by sylvain.joyeux (Sylvain Joyeux) almost 4 years ago

  • ruby -v changed from 1.9.3p484, 2.0.0p353 to 1.9.3p484, 2.0.0p353, 2.1.2

Ping ? Still happening on ruby 2.1.2p95

Updated by hsbt (Hiroshi SHIBATA) almost 4 years ago

  • Description updated (diff)
  • Status changed from Open to Feedback

2.1.2 is too old version. Please try with Ruby 2.1.6

Updated by byroot (Jean Boussier) over 3 years ago

  • ruby -v changed from 1.9.3p484, 2.0.0p353, 2.1.2 to 1.9.3p484, 2.0.0p353, 2.1.2 2.1.6p336 2.2.1p85
$ ruby -v
ruby 2.1.6p336 (2015-04-13 revision 50298) [x86_64-darwin14.0]
$ cat test.rb 
 $LOAD_PATH.unshift File.join(Dir.pwd, 'a')
 require 'test.rb'
 $LOAD_PATH.unshift File.join(Dir.pwd, 'b')
 require 'test.rb'

$ ruby test.rb 
a

It's still a problem in 2.1.6, and 2.2.1 as well

Updated by sylvain.joyeux (Sylvain Joyeux) over 2 years ago

  • Backport deleted (1.9.3: UNKNOWN, 2.0.0: UNKNOWN)
  • ruby -v changed from 1.9.3p484, 2.0.0p353, 2.1.2 2.1.6p336 2.2.1p85 to 1.9.3p484, 2.0.0p353, 2.1.2 2.1.6p336 2.2.1p85 2.3.1p112

and on 2.3.1

Updated by matz (Yukihiro Matsumoto) over 2 years ago

  • Status changed from Feedback to Rejected

I'd like to keep compatibility rather than reducing confusion slightly.
In any way, modifying $LOAD_PATH on the fly is not encouraged in modern Ruby.

Matz.

Also available in: Atom PDF