以下のコード スニペットがあります。
line_sub = Regexp.new(/\s+|"|\[|\]/)
tmp = Array.new
# reading a file
while line = file.gets
...
tmp[0],tmp[1] = line.to_s.scan(/^.*$/).to_s.split('=')
#remove unwanted characters
tmp.collect! do |val|
val.gsub(line_sub, "")
end
...
end
しかし、コードを実行するとエラーが発生します:
undefined method `gsub' for nil:NilClass (NoMethodError)
ここで何かが間違っているようです:
tmp.collect! do |val|
val.gsub(line_sub, "")
end
何か案が?