Forum: Ruby Look up objects by object_id

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
exiquio (Guest)
on 2008-11-10 23:11
(Received via mailing list)
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.
Robert K. (Guest)
on 2008-11-10 23:30
(Received via mailing list)
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.html#M006793

  robert
Brian C. (Guest)
on 2008-11-10 23:32
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.
exiquio (Guest)
on 2008-11-11 00:00
(Received via mailing list)
On Nov 10, 4:30 pm, Brian C. <removed_email_address@domain.invalid> wrote:
> 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-forum.com/.

thanks for the help
This topic is locked and can not be replied to.