undefined 方法 '+' for nil:NilClass (NoMethodError) ruby



尝试构建一个PPTX到scorm转换器。我得到一个错误NoMethodError未定义的方法' +' NilClass。我想这可能是由于一个已定义的方法。

dir = ARGV.shift
dest = ARGV.shift
pptx = dir + "/presentation.pptx"
lis = []`enter code here`
STDERR.puts "Copy template => #{dest}"
FileUtils.cp_r "template", dest
Dir["#{dir}/*.PNG"].each do |file|
STDERR.puts "Copy #{file} => #{dest}/img"
FileUtils.cp file, "#{dest}/img/"
STDERR.puts "Creating thumb #{file} => #{dest}/img/thumb"
name = file.split(///).last
system "/usr/bin/convert", "-scale", "200x", file, "#{dest}/img/thumb/#{name}"
lis.push name
end
ordered = lis.sort_by { |x| x[/d+/].to_i }

DIR为nil

如果你调试你的代码如下:

puts dir.nil? # true
因此,为了运行这段代码,必须为ruby shell提供2个参数,如下所示:
ruby test.rb DIRECTORY_NAME DESTINATION_NAME

相关内容

最新更新