From: Intransition Date: 2010-06-14T04:35:57+09:00 Subject: Re: Loading a module without polluting my namespace On Jun 13, 2:33 pm, Hagbard Celine wrote: > Hey folks! > > In my current project I try to load a module dynamically. Which is > basically no problem due to 'require` accepting filenames as well. My > problem is that I'd totally pollute my namespace. I thought of something > like the following: > > def load_module(filename) >   module NamespaceGuard  # Just a random name >     require filename >     # Take a care of the loaded module >   end >   # My namespace is clean again > end > > But Ruby's syntax apparently forbids module definitions in methods. I'd > be very glad if anyone could help me with this problem. Usually the file you are loading has the "protective" namespace. Eg. # namespace_guard.rb module NamespaceGuard ... end # main.rb require 'namespace_guard'