From: David Vallner Date: 2006-08-27T19:54:34+09:00 Subject: Re: Referencing an object through it's id string. Ken Bloom wrote: > On Sun, 27 Aug 2006 12:16:11 +0900, David Vallner wrote: > >> Alexandre Hudelot wrote: >>> Hello, how does one set a pointer to foo using an id string obtained >>> through foo.object_id for instance? >>> >>> Thanks in advance >>> >> Considering that object ids are only valid throughout one interpreter >> run... I'm curious: why pass around the object id instead of the object >> itself? > > Have a look at how weakref.rb is implemented. It keeps track of the > objects it's referencing by object id, because the garbage collector can't > follow those, but the references can get their objects back > using ObjectSpace._id2ref (assuming they haven't been garbage collected). I figured as much, but that was the only behaviour I could think of that I'd implement using this. And since it's in the standard library, I'd also probably use those weakrefs instead of rolling my own - I'm still living in the (naive?) idea that code that gets promoted into standard libraries works better than my implementations would. But then I still wonder. Why pass around object ids instead of weakrefs or object references themselves? David Vallner