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
是的,这是有效的,是有道理的。谢谢! –