From: Thomas Sawyer Date: 2011-07-07T04:36:26+09:00 Subject: [ruby-core:37831] [Ruby 1.9 - Bug #4969] Subtle issue with require Issue #4969 has been updated by Thomas Sawyer. @Aaron Yea, the problem isn't with loading a file *of* wedge. It has to do with what wedge does. The code I presented is a slightly simplified "wedge" in the project itself. The wedge gem is a lot like polyglot, but works a bit differently. And was originally created to handle the issue of loading ruby/gem files while by-passing any possible name conflicts. Of course it can be use for other things too, but that's what my current use case is. I am going to do some more in-depth research on this so hopefully I can come back with more specific details on what's causing the problem. Please let me know if you have any ideas. Thanks. ---------------------------------------- Bug #4969: Subtle issue with require http://redmine.ruby-lang.org/issues/4969 Author: Thomas Sawyer Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: - If I have a library with same name as Ruby standard library in load path (as an example): lib/abbrev.rb There is conflict with loading. Ok, I work around: require 'rbconfig' # Notice that rubylibdir takes precendence. LOCATIONS = ::RbConfig::CONFIG.values_at( 'rubylibdir', 'archdir', 'sitelibdir', 'sitearchdir' ) # def require_ruby(file) LOCATIONS.each do |loadpath| if path = lib_find(loadpath, file) return path end end raise LoadError, "no such file to load -- #{fname}" end private SUFFIXES = ['.rb', '.rbw', '.so', '.bundle', '.dll', '.sl', '.jar'] # Given a +loadpath+, a file's relative path, +relname+, and # options hash, determine a matching file exists. Unless +:load+ # option is +true+, this will check for each viable Ruby suffix. # If a match is found the full path to the file is returned, # otherwise +nil+. def lib_find(loadpath, relname) if SUFFIXES.include?(File.extname(relname)) abspath = File.join(loadpath, relname) File.exist?(abspath) ? abspath : nil else SUFFIXES.each do |ext| abspath = File.join(loadpath, relname + ext) return abspath if File.exist?(abspath) end end nil end Now I can do: require 'abbrev' require_ruby 'abbrev' And it works fine. But, if I do: require_ruby 'abbrev' require 'abbrev' The second is not loaded because somehow it seems to confuse it for the first in $LOADED_FEATURES. I realize this is a very subtle issue and not likely to effect most people, but it presents a big problem for some of my work (e.g. wedge gem) How is Ruby confusing the two? Can it be fixed? Or is there at least a work around? -- http://redmine.ruby-lang.org