Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to recursively require all files in a directory in Ruby?

I am working on an API that needs to load all of the .rb files in its current directory and all subdirectories. Currently, I am entering a new require statement for each file that I add but I would like to make it where I only have to place the file in one of the subdirectories and have it automatically added.

Is there a standard command to do this?

like image 795
juan2raid Avatar asked Dec 04 '09 21:12

juan2raid


1 Answers

In this case its loading all the files under the lib directory:

Dir["#{File.dirname(__FILE__)}/lib/**/*.rb"].each { |f| load(f) }
like image 179
Filipe Miguel Fonseca Avatar answered Sep 23 '22 06:09

Filipe Miguel Fonseca