require is actually a method, it is Kernel#require (which calls rb_require_safe ) so that you can at least do your hacking in the headless version. If you like such a thing.
- The orignal alias requires a path
- If an absolute path is passed, call the original require method
- Iterate over the loading path by creating an absolute path and calling the original require method.
Just for fun, I had a quick bash, the prototype of which is below. This is not fully verified, I have not tested the semantics of rb_require_safe , and you will probably also need to look at #load and #include for completeness - and this remains a patch of the Kernel monkey. Perhaps this is not entirely monstrous, but it is certainly a hack. Your call if it is better or worse than messing with the global variable $:
module Kernel alias original_require require
Examples:
require 'mymod' require 'mymod', '/home/me/lib' require 'mymod', [ '/home/me/lib', '/home/you/lib' ]
source share