# \#\<Object:0x2c1c8f0\> \<--- why is the displayed number == obje

**URL:** <https://www.ruby-forum.com/t/object-0x2c1c8f0-why-is-the-displayed-number-obje/106120>\
**Category:** Ruby\
**Created:** [June 6, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/object-0x2c1c8f0-why-is-the-displayed-number-obje/106120 "2007-06-06T17:11:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Meinrad\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@Meinrad\_R](https://www.ruby-forum.com/u/Meinrad_R)\
**Post date:** [June 6, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/object-0x2c1c8f0-why-is-the-displayed-number-obje/106120/1 "2007-06-06T17:11:51Z")

</div>

irb(main):001:0\> VERSION  
=\> “1.8.5”  
irb(main):002:0\> o=Object.new  
=\> #Object:0x2c1c8f0  
irb(main):003:0\> ObjectSpace.\_id2ref 0x2c1c8f0  
RangeError: 0x2c1c8f0 is not id value  
from (irb):3:in `\_id2ref’  
from (irb):3  
irb(main):004:0\> ObjectSpace.\_id2ref 0x2c1c8f0/2  
=\> #Object:0x2c1c8f0  
irb(main):005:0\>

I think that is pretty confusing. I am sure there is a good reason for  
this. But, don’t you think it’d be better to display the real  
object\_id instead of the doubled value?

– henon

---

<div class="post-metadata">

**Author:** ![Meinrad\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@Meinrad\_R](https://www.ruby-forum.com/u/Meinrad_R)\
**Post date:** [June 6, 2007, 5:20pm UTC](https://www.ruby-forum.com/t/object-0x2c1c8f0-why-is-the-displayed-number-obje/106120/2 "2007-06-06T17:20:53Z")

</div>

I agree

2007/6/6, Meinrad R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Meinrad\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@Meinrad\_R](https://www.ruby-forum.com/u/Meinrad_R)\
**Post date:** [June 6, 2007, 5:21pm UTC](https://www.ruby-forum.com/t/object-0x2c1c8f0-why-is-the-displayed-number-obje/106120/3 "2007-06-06T17:21:53Z")

</div>

In message  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), “Meinrad  
Recheis” wri  
tes:

> irb(main):005:0\>  
> I think that is pretty confusing. I am sure there is a good reason for  
> this. But, don’t you think it’d be better to display the real  
> object\_id instead of the doubled value?

Maybe it would. That said, Object.object\_id works as expected, so this  
only affects irb’s display.

(The reason, presumably, is that the ID is left-shifted by one, because  
objects with a 1 in the low-order bit are fixnums.)

-s

---

<div class="post-metadata">

**Author:** ![Meinrad\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@Meinrad\_R](https://www.ruby-forum.com/u/Meinrad_R)\
**Post date:** [June 6, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/object-0x2c1c8f0-why-is-the-displayed-number-obje/106120/4 "2007-06-06T17:35:55Z")

</div>

On 06.06.2007 17:10, Meinrad R. wrote:

> irb(main):005:0\>
> 
> I think that is pretty confusing. I am sure there is a good reason for  
> this. But, don’t you think it’d be better to display the real  
> object\_id instead of the doubled value?

The output of #inspect is not meant to give you any means to get at the  
original object although it may seem so at times. Having said that,  
#object\_id and #inspect are completely unrelated and it’s just an  
implementation artifact that some classes actually return something that  
resembles the object id.

As far as I remember this list you are the first one that mentions this.  
So it’s probably not that big an issue (at least not as confusing as  
“singleton class” :-))

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![Meinrad\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@Meinrad\_R](https://www.ruby-forum.com/u/Meinrad_R)\
**Post date:** [June 7, 2007, 5:39pm UTC](https://www.ruby-forum.com/t/object-0x2c1c8f0-why-is-the-displayed-number-obje/106120/5 "2007-06-07T17:39:51Z")

</div>

On 6/6/07, Robert K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > =\> #Object:0x2c1c8f0  
> > resembles the object id.
> 
> As far as I remember this list you are the first one that mentions this.  
> So it’s probably not that big an issue (at least not as confusing as  
> “singleton class” :-))
> 
> Kind regards
> 
> ```
> robert
> 
> ```

Robert,  
Thanks for your answer. I came across it while debugging a running  
application via an eval console. It’s not really a problem because I  
know that I need to divide the displayed id by 2 to get the object. I  
posted it just because ruby didn’t work as I expected it to … which  
is completely against the principles of the language.

cheers,  
– henon

---

<div class="post-metadata">

**Author:** ![Meinrad\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@Meinrad\_R](https://www.ruby-forum.com/u/Meinrad_R)\
**Post date:** [June 7, 2007, 6:10pm UTC](https://www.ruby-forum.com/t/object-0x2c1c8f0-why-is-the-displayed-number-obje/106120/6 "2007-06-07T18:10:55Z")

</div>

On 07.06.2007 17:39, Meinrad R. wrote:

> > > irb(main):004:0\> ObjectSpace.\_id2ref 0x2c1c8f0/2  
> > > implementation artifact that some classes actually return something that  
> > > resembles the object id.
> > 
> > As far as I remember this list you are the first one that mentions this.  
> > So it’s probably not that big an issue (at least not as confusing as  
> > “singleton class” :-))
> 
> Thanks for your answer. I came across it while debugging a running  
> application via an eval console. It’s not really a problem because I  
> know that I need to divide the displayed id by 2 to get the object.

Well, but that won’t work for all cases.

> I  
> posted it just because ruby didn’t work as I expected it to … which  
> is completely against the principles of the language.

That’s only one way to look at it. The other way is of course to assume  
that your expectations were “wrong” (whatever that means). 🙂

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![Meinrad\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@Meinrad\_R](https://www.ruby-forum.com/u/Meinrad_R)\
**Post date:** [June 7, 2007, 7:05pm UTC](https://www.ruby-forum.com/t/object-0x2c1c8f0-why-is-the-displayed-number-obje/106120/7 "2007-06-07T19:05:02Z")

</div>

On 6/7/07, Robert K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Well, but that won’t work for all cases.  
> Nor for all versions of ruby. The relationship between object\_id and  
> the VALUE representation for various classes has been changing even  
> within the 1.8.x stream. $Diety only knows what implementations like  
> JRuby, rubinius, IronRuby etc would use for inspect which is the  
> method which produces what you see after the ==\> in irb, or call  
> Kernel#p

Inspect is intended to be used for the ‘programmer’ representation of  
an object, to help activities like debugging. So in the case of  
classes like Object that representation will likely have some info  
useful to the current internal implementation, and unless it’s  
documented somewhare, there’s no guarantee that it won’t change.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![Meinrad\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@Meinrad\_R](https://www.ruby-forum.com/u/Meinrad_R)\
**Post date:** [June 7, 2007, 7:26pm UTC](https://www.ruby-forum.com/t/object-0x2c1c8f0-why-is-the-displayed-number-obje/106120/8 "2007-06-07T19:26:04Z")

</div>

On Jun 6, 8:21 am, removed\_email\_address@domain.invalid (Peter S.) wrote:

> (The reason, presumably, is that the ID is left-shifted by one, because  
> objects with a 1 in the low-order bit are fixnums.)

When I came across this behavior, this was also my best guess as the  
reason.
