From: Wilson Bilkovich Date: 2005-09-14T00:23:08+09:00 Subject: Re: Optimizing a single slow method On 9/12/05, Hugh Sasse wrote: > > File.open(file, "rb") do |io| > > io.each_line do |line| > > Coould do that in one I think > File.open(file, 'rb').each_line do |line| > because you don't use io again. > I used this form frequently in the past, but then someone explained to me that it never closes the file handle. Because File.open doesn't see an associated block, it doesn't handle the cleanup for you. The "block inside block" version guarantees cleanup, even if an exception is thrown. Other than that, I think your suggestions are good. --Wilson.