dynamic require

  • Thread starter Rajarshi Chakravarty
  • Start date
R

Rajarshi Chakravarty

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
 
T

Tony Arcieri

[Note: parts of this message were removed to make it a legal post.]

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.
 
J

Jesús Gabriel y Galán

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top