Faire un zip d'une arborescence en ruby avec rubyzip

Donc le petit code cadeau du jour : faire un zip d'une arborescence en ruby (1.8 et 1.9) avec rubyzip.

require 'rubygems'
require 'zip/zip'
require 'zip/zipfilesystem'
# Dossier à explorer
rootdir = "Mon_dossier"
base_path = [rootdir]
base_zip_path = [rootdir]
# Fonction qui explore une arborescence et ajoute les fichiers dans un zip
def explore_and_add(zipf, pathrep, zippathrep)
  zipf.mkdir(File.join(zippathrep))
  
  (Dir.entries(File.join(pathrep)) - ['.', '..']).each{ |entry|
    diskpath = File.join(pathrep, entry)
    if not File.directory?(diskpath) then
      # Ajoute le fichier dans le zip avec la même structure
      zipdiskpath = File.join(pathrep, entry)
      puts diskpath
      zipf.add(
        diskpath,
        zipdiskpath
      )
    else
      # Ajoute le répertoire et descend dans l'arborescence
      pathrep << entry
      zippathrep << entry
      zipf = explore_and_add(zipf, pathrep, zippathrep)
      pathrep.delete_at(-1)
      zippathrep.delete_at(-1)
    end
  }
  return zipf
end
filename = "zip_" + Time.now.to_i.to_s + ".zip"
Zip::ZipFile.open(filename, Zip::ZipFile::CREATE) { |zipfile|
  zipfile = explore_and_add(zipfile, base_path, base_zip_path)
}