file.new 和 file.open 的区别
file.open 可以在后面与块关联而 file.new 不可以
a = file.new("aa.rb","w") a.close b = file.open("bb.rb"){|f| f}
file.new这个例子, if an exception is raised while
processing the file, the call to file.close may not happen. Once the file variable goes out of scope, then garbage collection will eventually close it, but this may not happen for a while. Meanwhile, resources are being held open.This doesn’t happen with the block form of File.open. If an exception is raised inside the block,the file is closed before the exception is propagated on to the caller