From: Jim Freeze Date: 2001-03-03T00:53:30+09:00 Subject: [ruby-talk:11901] Class Destructor? I have a class where the initializer takes a filename and opens a file. The class has several methods to let the user get information from the file. The problem is, I don't know how to have the class close the file automatically like a destructor would in C++. (Maybe I have missed something big here) I see 2 options: 1) Put the burden on the user with #begin #end begin c = Myclass.new("file") c.meth1 c.meth2 ensure c.close end 2) Or I could store the file pointer in the class and have each method open the file, move to the proper location, do its thing, save the file pointer, close the file. But this seems kind of kludgy. Any other ideas out there? Thanks ========================================================= Jim Freeze jim@freeze.org --------------------------------------------------------- "So, it should be relatively easy ... this is the phrase I use when someone else is the most obvious person to do something." Harry Ohlsen =========================================================