From: Eric Hodel Date: 2010-11-16T10:41:41+09:00 Subject: [ruby-core:33206] Repost: Avoiding $LOAD_PATH pollution I discussed this with Matz at RubyConf. Matz asked me to bump the discussion of this so we could learn of any objections to this proposal that may have been discussed on ruby-dev. Original message follows: Last year Nobu asked me to propose an API for adding an object to $LOAD_PATH (instead of a String) that could do the work of finding paths to load. The reason was to avoid the pollution of $LOAD_PATH that RubyGems causes as it activates multiple gems. I have created a proof-of-concept implementation called fancy_require: http://github.com/drbrain/fancy_require specifically: http://github.com/drbrain/fancy_require/blob/master/lib/fancy_require.rb The API I propose for the lookup object added to $LOAD_PATH is: The lookup object pushed onto $LOAD_PATH must respond to #path_for. The feature being required (file name) will be passed in by Kernel#require. The lookup object must return the path to the feature, true, false or nil. If nil is returned Kernel#require will continue to the next item in the load path. If true or false are returned the lookup object handled loading the file and recording it in $LOADED_FEATURES. The boolean will be returned as plain require. The true/false behavior would allow the lookup object to load features from a non-file object like a tarball. I think Ruby should also add a method that would determine if a feature is in $LOADED_FEATURES. Maybe Kernel#loaded?(feature). This is not strictly necessary.