Feature #12858
openSupporting batch-requiring of files in ruby
Description
Hello. This is a very short proposal, unlike some of my previous
ones; and it also is hopefully possibly better than some of my
other proposals before.
Could we have a way to batch-require .rb files from a directory?
Right now we can do:
require 'foo/bar.rb'
require 'foo/boo.rb'
require 'foo/bii.rb'
But this is a bit cumbersome, especially if you have lots of
files to manually specify here.
We can do first grab these via Dir[] which works fine and
then invoke require() on each entry. This also works fine
and I am doing this in some of my gems, but it is a
cumbersome nonetheless.
I was thinking of either of the following two changes perhaps:
require_directory 'foo' # This would be similar to:
require_directory 'foo/'
This new method would then attempt a Dir[] before batch-requiring
the specified files via require().
Alternatively, or additionally, perhaps require() itself
could support '*'? Then we could have this for require
itself like:
require 'foo/*.rb'
I am not sure if this has been suggested before; there
are a few gems that try to solve this but I was wondering
if it could be added to ruby as a core functionality
itself. Note that while my examples above center primarily
around .rb files, it could of course work for .so files
too, just following require() policy anyway - my main
point was about batch-requiring files more easily in
ruby.
Thanks for reading!
PS: It could work for load() too but I personally seem to
use require() like +98% of the time so I don't care that
much about load() really.