Oh, this is neat. Check out the rubyzip gem:
rubyzip also features the
zip/ziprequire.rb module (source) which allows
ruby to load ruby modules from zip
archives.
(Update: The ziprequire.rb is no longer present in the rubyzip gem, but the source link appears to contain its old content nonetheless.)
Like so. This is just slightly modified from their example:
require 'rubygems'
require 'zip/zipfilesystem'
require 'zip/ziprequire'
Zip::ZipFile.open("/tmp/mylib.zip", true) do |zip|
zip.file.open('mylib/somefile.rb', 'w') do |file|
file.puts "def foo"
file.puts " puts 'foo was here'"
file.puts "end"
end
end
$:.unshift '/tmp/mylib.zip'
require 'mylib/somefile'
foo # => foo was here
You don't have to use the rubyzip library to create the zipped library, of course. You can use CLI zip for that.