From: E S Date: 2004-12-29T07:19:00+09:00 Subject: Re: Namespaces, inverted > L�hett�j�: "Robert Klemme" > "Joel VanderWerf" schrieb im Newsbeitrag > news:41D0E5EF.1040308@path.berkeley.edu... > > eero.saynatkari@kolumbus.fi wrote: > > [Snip] > > class String > > def as mod > > {:name => self, :module => mod} > > end > > end > I don't like the idea of the as method as it cannot be used reasonable in > other circumstances as module loading. The code really does not belong into > class String IMHO. Agreed. It just looked better :) I suppose a top-level method would have done as nicely for this how-it-can-be-done-now implementation. > We have Kernel#load [1] with a similar functionality already. Currently it > accepts an additional parameter to enforce wrapping of the file in an > anonymous module. That could be extended to accept a module as well; that > then would be the module used. Then we can do > > load "foo.rb" # not wrapped > load "foo.rb" # wrapped in an anonymous module > load "foo.rb", MyExternal # wrapped in MyExternal Good. I had to rely on a 1.6 reference knowledge and didn't recall the second parameter. Implementing it this way would, certainly, require a change at the core level so an RCR might be appropriate. I can write it up, I suppose. I'm still partial to 'import' vs. 'require', though :) > Additionally / Alternatively it could be useful to have a per module require > like this: > > class Module > def require(*files) > # puts "loading in module #{self}: #{files.inspect}" > @loaded ||= {} > files.each do |f| > unless @loaded[f] > # real load code that wraps contents of f in self > @loaded[f] = true > end > end > end > end > > Then we could do > > module Foo > require "bar" > end > > and even if we do the same later again, "bar" is only loaded once (see [2]). Looks nice, although the functionality is somewhat overlapping, no? > Kind regards > > robert E