From: Rajarshi Chakravarty on
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
--
Posted via http://www.ruby-forum.com/.

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

On Sun, Aug 8, 2010 at 11:41 PM, Rajarshi Chakravarty
<raj_plays(a)yahoo.com>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.

--
Tony Arcieri
Medioh! A Kudelski Brand

From: Jesús Gabriel y Galán on
On Mon, Aug 9, 2010 at 7:41 AM, Rajarshi Chakravarty
<raj_plays(a)yahoo.com> 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.