title: How to unzip a file with ruby
body: <p>Okay I've found the following code for unzippping a file with Ruby.</p>
  
  <pre><code>def unzip_file (file, destination)
      Zip::ZipFile.open(file_path) { |zip_file|
          zip_file.each { |f|
              f_path=File.join("destination_path", f.name)
              FileUtils.mkdir_p(File.dirname(f_path))
              zip_file.extract(f, f_path) unless File.exist?(f_path)
          }
      }
  end
  </code></pre>
  
  <p>Above this I'm using the following to ensure the needed gems are installed.</p>
  
  <pre><code>begin
      require 'rubygems'
  rescue LoadError
      'gem install rubygems'
  end
  begin
      require 'zip/zip'
  rescue LoadError
      'gem install rubyzip'
  end
  </code></pre>
  
  <p>So when I call unzip_file I get the following error:</p>
  
  <pre><code>in `unzip_file': uninitialized constant Zip (NameError)
  </code></pre>
  
  <p>What am I doing wrong?
  Thanks!</p>