From: Andrew Walrond Date: 2005-07-02T20:32:15+09:00 Subject: Re: Loading a file without cluttering the global namespace This is what I do in Heretix: # # Packages is a container class for all package classes. # it is used to prevent the Package class names from polluting the global namespace # module Packages # Some package files need to 'require' other package files. The inline function # ensures that the inclusion occurs within the Packages module as load() and require() # both pollute the global namespace. If package files need to include other package # files (eg perl module needs perl.rb) they must use inline() rather than require() # or load(), which are removed to prevent their use (in the Package.load() function). # def Packages.inline(filename) Packages.module_eval(IO.read(filename),filename) end end def Package.load() # Load the package classes into the Packages namespace. load() and require() # both pollute the global namespace, so use some trickery instead. If package # files need to include other package files (eg perl module needs perl.rb) # they must use inline() rather than require() or load(), which are removed # so that relevant warnings are produced when package developers forget... # Kernel#remove_method :require Kernel#remove_method :load HERETIXDIR.cd { Dir.glob('core/packages/*.rb').each { |fn| Packages.inline(fn) } Dir.glob('contrib/packages/*.rb').each { |fn| Packages.inline(fn) } } ...