Gregory Seidman wrote: > On Fri, May 19, 2006 at 04:23:45PM +0900, Alex Young wrote: <snip> > } A possible solution sprung to mind: how does the following syntax look? > } > } require 'foo', :into => 'Bar' > } require 'qux', :into => 'Wibble::Spang' > [...] > } Any thoughts? Has this been discussed to death before my time? Is it > } obviously stupid? > > I don't care for the :into => syntax, myself. Fair enough :-) > } It's just struck me that if we're getting help from the interpreter > } anyway, this might be possible: > } > } require 'foo' into Bar > [...] > > Nicer, but I consider the whole into thing superfluous. Consider the > following implementation: <snip implementation I'll have to go away and Study...> I've got a bit of a soft spot for natural language-ish syntax, but that's just personal preference talking. > You can then use... > > RequireWithinNamespace::require 'qux', 'Wibble::Spang' Given that my plan was to alias away (or somehow supplement) the existing Kernel#require, I didn't want to hijack the second parameter because I don't know what's going on with require_gem. As I understand it, require_gem is being deprecated in favour of plain-old require, but require_gem handles version requirements which (I imagine) could get tacked on to require. Passing named parameters with a hash seems to be the cleanest way to please everyone :-) > ...or even... > > # no need for quotes around the namespace > RequireWithinNamespace::require_within 'qux', Wibble::Spang That's a neat trick - the only reason I had the quotes there in the first place was because I wasn't sure it was possible to get rid of them without triggering warnings. > ...or, since it is a drop-in replacement for require, you can add... > > module Kernel > alias :require_no_namespace :require > > def require(filename, context = nil) > RequireWithinNamespace.require_within(filename, > context, :require_no_namespace) > end > end And *that* is what I think I'll be using from here on in. Very cool. <snip> > See > http://redcorundum.blogspot.com/ <snip> Bookmarked! Thanks for that, good to know I'm not entirely barking. -- Alex