2
爲什麼此代碼只修改數組中的最後一個文件?這些文件都可由我的用戶讀取和寫入。搜索/替換奇怪
%w(views/layout.rhtml views/admin/layout.rhtml).each do |file|
text = File.read(file)
File.open(file, 'w+') do |f|
f << text.gsub(/\?v=(\d+)/, "?v=#{$1.to_i + 1}")
end
end
是的,這是有效的,是有道理的。謝謝! –