require
and load
are just methods like any other. You can undefine them, redefine them, override them, hook them, wrap them to do anything you want. In fact, that's exactly how RubyGems works.
Now, I don't know whether someone has already implemented this for you, but I actually remember some discussions about this on the ruby-talk mailinglist.
However, there are some examples of loading library code from alternative locations that you can look at, and maybe copy / adapt what they are doing for your purpose:
- http_require does pretty much what it sounds like: it allows you to
require
an HTTP URI
- Crate is a Ruby packaging tool which packages a Ruby application into a single binary and a couple of SQLite databases; it modifies
require
to load libraries out of an (encrypted) SQLite database instead of the filesystem
- and of course I already mentioned RubyGems