我有以下代码片段:
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
任何的想法?