常规处理:
File.open("sampel.txt") do |file| file.each_line do |line| print line end end
上式与下式等价
file = File.open("sample.txt") begin file.each_line do |line| print line end ensure file.close end
常规处理:
File.open("sampel.txt") do |file| file.each_line do |line| print line end end
上式与下式等价
file = File.open("sample.txt") begin file.each_line do |line| print line end ensure file.close end
转载于:https://www.cnblogs.com/liuyang92/p/5898243.html