Dynamic require

Hi,
Is there a syntax of ‘require’ that can dynamically pick up all source
files searching in sub directories?

I have many subdirectories under my root directory and each has some .rb
files.
The names and number of files in each subdirectory are different.
My main program is in the root directory.
It needs to be able to access all the .rb files.

Regards,
Raj

On Sun, Aug 8, 2010 at 11:41 PM, Rajarshi C.
[email protected]wrote:

Hi,
Is there a syntax of ‘require’ that can dynamically pick up all source
files searching in sub directories?

There’s my require_all gem, which will not only do this, but
resolve dependencies between files

http://github.com/tarcieri/require_all

That said, I’m not really a fan of this method anymore. It’s slow and
has
thread safety issues. I’ve been meaning to write a “sequel” to
require_all,
but never gotten around to it.

On Mon, Aug 9, 2010 at 7:41 AM, Rajarshi C.
[email protected] wrote:

Hi,
Is there a syntax of ‘require’ that can dynamically pick up all source
files searching in sub directories?

I have many subdirectories under my root directory and each has some .rb
files.
The names and number of files in each subdirectory are different.
My main program is in the root directory.
It needs to be able to access all the .rb files.

I did this once:

Dir[“#{libdir}//.rb”].each do |x|
puts “requiring #{File.join(File.dirname(x), File.basename(x,
“.rb”))}”
require File.join(File.dirname(x), File.basename(x, “.rb”))
end

it will require all “*.rb” files under a folder. Hope this helps,

Jesus.