[英]rubyzip error undefined method 'join' for Zip::File:Class
following the documentation for rubyzip 2.3.2, I have this method:按照 rubyzip 2.3.2 的文档,我有这个方法:
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)这会产生一个错误:Zip::File:Class 的未定义方法 'join' (NoMethodError)
This does create a "testing.zip" file, but it is empty这确实创建了一个“testing.zip”文件,但它是空的
the files live in the same directory and I've tested that with: puts files the files are returned这些文件位于同一目录中,我已经通过以下方式进行了测试: puts files the files are returned
the fix was changing "File.join" to "::File.join"修复是将“File.join”更改为“::File.join”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.