From: Devin Mullins Date: 2005-12-16T22:57:23+09:00 Subject: Re: [ANN] scoped_require 0.0 Mauricio Fernandez wrote: >You also dislike alias_method, don't you? ;-) > > I tried to pollute the namespace as little as possible. (And then I refactored and created Module#find_or_create_module, but whatever.) I also tried to be as 'cute' as possible (but that was a tertiary concern). >wouldn't that break code like > ># foo.rb >class String ># instead of class ::String > def foo; "foo #{self}" end >end > > Good point, yes... I suppose I could inject #clones of the toplevel namespace's constants into the container module... 'twould be a little performance-heavy, so maybe I'd make that an option, � la: require 'foo', :module => :Foo, :import => [String, Hash] Would that work? Do you have a better idea? >There's another tricky issue regarding the transitivity of scoped_require: > ># a.rb >require 'b', :module => :B >... >#================================================================= ># b.rb >require 'something' >... >#================================================================= ># app.rb >require 'a', :module => :A > >Should 'something' be scoped to B, A, A::B, or not at all? >And if it is loaded under some module, should it be added to $"? > > I should be deadling with that, now. Without running the above code, I'm pretty sure 'something'll get loaded under A::B. And my require override uses @__require_feature rather than $", so it's specific to each container module. Although, admittedly, I probably could use a couple of unit tests to test the interaction between scoped requires and non-scoped requires (and $"). >So it seems scoped_require would work best with 1-file libs that don't >mess with code classes. In other cases, it could still be useful: there's >nothing wrong with encouraging lecture ;-) > > Well, definitely more than one file -- it was in my requirements (using RubyfulSoup) that nested requires work.* But yeah, I couldn't imagine that require 'rails', :module => :Rails would work. :P Thanks for the feedback. I may add the import thing later. Devin * Well, sort of. It's actually the main file, rubyful_soup.rb, that defines the Tag class, not its dependency, sgml_parser.rb, so I could've gotten away with not handling nested requires. But I was having fun... :)