[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Look up objects by object_id

exiquio

11/10/2008 9:07:00 PM

So ruby objects have an object_id. What is the intended purpose of
these unique identifiers? Is their a method that allows one to
retrieve a object by object_id? Thanks in advanced.
3 Answers

Robert Klemme

11/10/2008 9:28:00 PM

0

On 10.11.2008 22:06, exiquio wrote:
> So ruby objects have an object_id. What is the intended purpose of
> these unique identifiers? Is their a method that allows one to
> retrieve a object by object_id? Thanks in advanced.

http://ruby-doc.org/core/classes/ObjectSpace.ht...

robert

Brian Candler

11/10/2008 9:30:00 PM

0

exiquio wrote:
> So ruby objects have an object_id. What is the intended purpose of
> these unique identifiers? Is their a method that allows one to
> retrieve a object by object_id? Thanks in advanced.

The object_id is an encoded version of the object reference and class.
For certain classes (e.g. Fixnum) you can decode the actual value. For
other classes it encodes the memory address where the object data
structure can be found.

If two object references have the same object_id, then they are the same
object.

As for retrieving by object_id, see ObjectSpace._id2ref(ref). There are
practical examples in drb/drb.rb and weakref.rb in the standard library
that you can look at.
--
Posted via http://www.ruby-....

exiquio

11/10/2008 9:58:00 PM

0

On Nov 10, 4:30 pm, Brian Candler <b.cand...@pobox.com> wrote:
> exiquio wrote:
> > So ruby objects have an object_id. What is the intended purpose of
> > these unique identifiers? Is their a method that allows one to
> > retrieve a object by object_id? Thanks in advanced.
>
> The object_id is an encoded version of the object reference and class.
> For certain classes (e.g. Fixnum) you can decode the actual value. For
> other classes it encodes the memory address where the object data
> structure can be found.
>
> If two object references have the same object_id, then they are the same
> object.
>
> As for retrieving by object_id, see ObjectSpace._id2ref(ref). There are
> practical examples in drb/drb.rb and weakref.rb in the standard library
> that you can look at.
> --
> Posted viahttp://www.ruby-....

thanks for the help