From: Hugh Sasse Date: 2005-11-26T01:30:37+09:00 Subject: Re: `finalize' method? On Sat, 26 Nov 2005, Daniel Schierbeck wrote: > Hugh Sasse wrote: > > On Sat, 26 Nov 2005, Daniel Schierbeck wrote: > > > > > I just think it's weird that PHP has destructors and Ruby doesn't ;) > > > > > > http://www.php.net/manual/en/language.oop5.decon.php > > > > I find this tricky too: the only model I can think of is that where > > you need destructors, your constructor desstructs, and you get at > > the object with a block, in the style of open("file"){|f| ...}; if > > you see what I mean. > > No, not really. I really can't stretch enough that I'm a noob... :) The braces, curly brackets, are a block. The CS people will tell you it is a closure. What it means is: In the current scope (local variables defined, etc) execute open("file") to open the file for reading, and then [when inside open it effectively calls yield] you will have a parameter which we'll call f, and we'll do something with it in the local scope until the closing brace of the block. On the closing brace, open will close the file for us. The oft' used each method behaves in a similar way. For an intro: http://www.rubycentral.com/book/tut_containers.html#S2 For info about using them with constructors: http://www.rubycentral.com/articles/insteval.html [...] > > > imagine the `finalize' method could be run, and afterwards, the object > > > could > > > be replaced with nil, maybe retaining the old object id. That way any > > > variables that point to the object will be nil. > > > > But there is only one nil in the system, so it can't have many ids. > > Could the object then by replaced by a reference to the nil object? Again, I'm > talking theoretically... Ruby doesn't have references, otherwise it could. > > > Cheers, > Daniel > Hugh