Reputation: 1019
It is proving difficult to find any documentation online that explains syntax for .irbc files.
When running irb, is it possible to ensure that .rb files in the current and subdirectories are pre-loaded.
So that whenever irb is run, irb automatically loads any/all .rb files within the current directory, and any sub directories.
If documentation for this does exist, then please inform so that this question can be closed.
Upvotes: 2
Views: 943
Reputation: 160551
.irbrc files can contain Ruby code, which will be executed.
You can write code to grab files in the current directory and its children, however that process can greatly slow IRB's startup as it descends through a hierarchy, especially if you try to start it in a Rails app's top directory, or a well-populated gems directory. And, at the same time, every file loaded will pollute IRB's namespace, load code you're very likely to NOT need, cause weird errors because a parameter wasn't given on the command-line, automatically fire off purges, internet connections, and anything else coded in the scripts.
In short I think it'd turn out to have some very negative side-effects that'd make you sorry.
Instead I'd recommend writing small wrapper scripts that load just the files you want and load those. They'll be faster and will do exactly what you want. Also become familiar with the -r
and -I
flags:
-r load-module Same as `ruby -r'
-I path Specify $LOAD_PATH directory
http://irb.tools/ and https://github.com/janlelis/irbtools are good reads to get the most out of IRB.
Upvotes: 3
Reputation: 462
Write require
commands in irbc file for whatever file you want to require in there. File name should be .irbrc
Reference: http://ruby-doc.org/stdlib-2.0.0/libdoc/irb/rdoc/IRB.html
Upvotes: 0