Reputation: 1
i am a newbie in ruby... I'm trying to convert media into a scorm package using what i found on github but i got an error while trying to run the script in the command prompt undefined method `gsub' for nil:NilClass
. I guess it may be due to a defined method. any idea on how i can remove this error ?
dir = ARGV.shift.gsub(/\/+$/, '')
index = nil
media = []
Dir["#{dir}/media/*.json"].each do |file|
id = JSON.parse(File.read(file))
base = file.gsub(/\/media\/.*\.json$/, '')
index = "#{base}/index.html"
name = File.basename file
media.push [name,id]
puts "#{name}: #{id}"
end
Upvotes: 0
Views: 4056
Reputation: 369536
As the error says, you are calling the method gsub
on an object that is an instance of NilClass
, in other words you are calling gsub
on nil
.
The error message tells you in which method and on which line this happens and how you got to that line of code. You will have to examine the error message to find the place in your code where you are calling gsub
on an object that is nil
, then you have to examine your code to find out why that object is nil
instead of a String
as you expect it to.
Upvotes: 3