From: Robert Klemme Date: 2004-05-11T20:38:53+09:00 Subject: Re: RCR: Unique Object for Each source file "David A. Black" schrieb im Newsbeitrag news:Pine.LNX.4.44.0405101131140.30906-100000@wobblini... > Hi -- > > On Tue, 11 May 2004, Bill Atkins wrote: > > > Each Ruby .rb file is currently executed within the class Object. So > > running "include ModuleX" in your main script file includes the > > methods of ModuleX into Object globally. This is messy. .... but might be desired (see below). And it can be avoided, either by using 'load' with wrap=true or by defining a module in the file and putting everything there. > > I propose that each file be executed within a new instance of Object. > > This way, running include in a file would cause that module to be > > included only within the scope of that file. IMHO this would break existing code: assume a file containing only method definitions without any modules, these methods then would not be available, would they? > I'm not seeing the problem here. If you include a module, that module > gets mixed in to whatever module or class called #include. So if it's > Object, you're mixing the module into Object. But usually it isn't, > and in any case it isn't connected with what's in which file. And then there is Kernel#load which already allows for wrapping in an anonymous module: http://www.ruby-doc.org/docs/rdoc/1.9/classes/Kernel.html#M001574 I'd rather suggest load to return the anonymous instance that was used in executing the code. That way, one can properly access all those methods defined in the file. Regards robert