Look up objects by object_id

E

exiquio

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.
 
B

Brian Candler

exiquio said:
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.
 
E

exiquio

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.

thanks for the help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top