Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

powerpoint - undefined method `+' for nil:NilClass (NoMethodError) ruby

trying to build a pptx to scorm converter. I get an error NoMethodError Undefined method `+' for NilClass. I guess it may be due to a defined method. any idea on how i can remove this error ?

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 }
question from:https://stackoverflow.com/questions/65880848/undefined-method-for-nilnilclass-nomethoderror-ruby

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

DIR is nil

If you debug your code as follows:

puts dir.nil? # true

So, in order to run this code you must provide the ruby shell with 2 arguments, as follows:

ruby test.rb DIRECTORY_NAME DESTINATION_NAME

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...