On Mar 31, 2006, at 2:58 PM, PrimaryKey wrote: >> How would you use static constructors/destructors? Perhaps we can >> show >> you Ruby equivalents. >> >> -- >> -- Jim Weirich > > Please consider the following (pseudo) C# example: > > public class AS400Server > { > static AS400 server; > > static AS400Server() > { > server = new AS400Connection("SERVERNAME"); > } > > static ~AS400Server() // This is not real C# > { > server.disconnect(); > } > > static int GetServer() > { > return server; > } > } > > I know this probably can be emulated using a singleton, I still > believe > having static destructors will be nice because: > > 1. I like the constructor/destructor symmetry in C++ > 2. It can be helpful for meta-programming purposes. My impression is > most languages try to implement the traditional OO tools on class > (static) level > > Thanks > > -- > Posted via http://www.ruby-forum.com/. > class AS400Server @server = AS400Connection.new def self.get_server @server end end As for a static deconstructor, can't really help you, I don't think classes are really ever GCed until the very end, anyway. however, you could do this: class AS400Server at_exit { @server.disconnect } end