From: Aa Aa Date: 2008-05-04T07:02:22+09:00 Subject: Re: Ruby Class documentation > In the upper lefthand corner there is Parent: IO, and IO is a > hyperlink to IO documentation. > IO contains the close method. Thanks, I probably missed that because it doesn't look like something you can click on :) > Related to this: > > It's usually better to use block form of File.open, than File.new and > File#close. > i.e. > instead of > > f = File.new('xxxx',''w') > f << "dfsdfsd" > f.close > > do > > File.open('xxxx','w') do |f| > f << "fdfdsfsdf" > end > > The file will be closed when the control exits from the block (even in > the case of an exception). > > File.new is usually used when you need to keep the file open longer > than a scope of one method. > (setting a member/attribute, returning open file from a method, etc.) > > J. Really useful tip, looks similar to the C# using statement. -- Posted via http://www.ruby-forum.com/.