Let's say you have a Ruby application you've written, and it consists of multiple files that you require
inside your code. You want to run this application on some remote machines. To make it easier to deploy this application, you want to distribute it as a single file (archive.) This is possible with the rubyzip
gem. Let's say your main application file (myapp.rb
) looks like this:
require "lib/mylib" require "lib/otherlib" require "vendorlib/something" # Do stuff.
Normally you might run your application with ruby ./myapp.rb
. To run it on another machine, we can use the zip/ziprequire
library in rubyzip
. First, make a zip file containing all your application files:
zip -r myapp.zip myapp.rb lib vendorlib
Copy myapp.zip
to the remote machine, and you can run it like this:
ruby -rubygems -Imyapp.zip -e 'require "zip/ziprequire"' -e 'require "myapp"'
See rubyzip documentation, specifically ziprequire.rb for more information.