rubyzip error undefined method 'join' for Zip::File:Class

111 Views Asked by At

following the documentation for rubyzip 2.3.2, I have this method:

def zip_files(zip_file_name, files)
  Zip::File.open(zip_file_name, Zip::File::CREATE) do |zipfile|
   files.each do |filename|
    zipfile.add(filename, File.join('.', filename))
   end
  end
end

files = ["test.txt", "test2.txt"]

zip_files("testing.zip", files)

this produces an error: undefined method 'join' for Zip::File:Class (NoMethodError)

This does create a "testing.zip" file, but it is empty

the files live in the same directory and I've tested that with: puts files the files are returned

1

There are 1 best solutions below

0
bradb On

the fix was changing "File.join" to "::File.join"