From: Daniel Berger Date: 2009-06-09T23:37:03+09:00 Subject: Re: [ANN] require_all 1.0.0: A wonderfully simple way to load your code > -----Original Message----- > From: bascule@gmail.com [mailto:bascule@gmail.com] On Behalf Of Tony > Arcieri > Sent: Tuesday, June 09, 2009 3:21 AM > To: ruby-talk ML > Subject: [ANN] require_all 1.0.0: A wonderfully simple way to load your > code > > require_all > > A wonderfully simple way to load your code. > > http://github.com/tarcieri/require_all/tree/master > > Tired of futzing around with require statements everywhere, littering > your > code with require File.dirname(__FILE__) crap? What if you could just > point > something at a big directory full of code and have everything just > automagically load regardless of the dependency structure? > > Wouldn't that be nice? Well, now you can! > require 'require_all' > > You can now require_all in a multitude of different ways: > require_all *args > > One of the easiest ways to require_all is to give it a glob, which will > enumerate all the matching files and load them in the proper order. For > example, to load all the Ruby files under the 'lib' directory, just do: > require_all 'lib/**/*.rb' > > If the dependencies between the matched files are unresolvable, it will > throw the first unresolvable NameError. > > Don't want to give it a glob? Just give it a list of files: > require_all Dir.glob("blah/**/*.rb").reject { |f| stupid_file(f) } > > Or if you want, just list the files directly as arguments: > require_all 'lib/a.rb', 'lib/b.rb', 'lib/c.rb', 'lib/d.rb' > > It's just that easy! Code loading shouldn't be hard. > Methodology > > I didn't invent the approach this gem uses. It was shamelessly stolen > from > Merb Trust me, Merb was not the first library to come up with Java style/globbing import statements. I remember this being discussed a *long* time ago, and it generally crops up from time to time on the mailing list. I'm pretty sure it was an RCR at one point (for altering the behavior of Ruby's own require), but I can't find it now. But, now that I'm looking on the RAA, I can't find a library for it. So, still a nice thing to have, thanks. :) Regards, Dan