Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save skorks/466442 to your computer and use it in GitHub Desktop.
Save skorks/466442 to your computer and use it in GitHub Desktop.
#recursively require all files in directory (and subdirectories)
Dir["#{File.dirname(__FILE__)}/squat/**/*.rb"].each {|file| require file }
#recursively require all files in directory but skip paths that match a pattern
Dir["#{File.dirname(__FILE__)}/squat/**/*.rb"].each do |file|
require file unless file =~ /\/model\//
end
@skorks
Copy link
Author

skorks commented Jul 9, 2010

A simple way to recursively require all ruby files in a directory structure, this is not really an ideal way as it doesn't take care of dependencies between requires, but it is quick and easy. If we do want to take care of the dependencies require_all gem is good, or can roll your own by catching exceptions and attempting to another pass at requiring all the ones that failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment