From: Dave Thomas Date: 2001-03-03T01:21:27+09:00 Subject: [ruby-talk:11904] Re: Class Destructor? Jim Freeze writes: > 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) One trick, if you have fairly localized access to the file, is to use a block MyClass.open("file") do |c| c.meth1 c.meth2 end where ::open is something like class MyClass # untried def MyClass.open(file) File.open(file) do |@f| yield self end end def meth1 @f.read.. # or whatever end Dave