Object id

S

Sea&Gull

u@l:~> ruby -v
ruby 1.8.1 (2003-12-25) [i686-linux]

u@l:~> ruby -w -e 'class C; end; c1 = C.new; p c1; puts c1.object_id'
#<C:0xb7d921c8>
-605253404

What id does the object "c1" have - 0xb7d921c8 or -605253404 ?
If -605253404, why it is negative?

Thanks for the answer!
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Object id"

|u@l:~> ruby -w -e 'class C; end; c1 = C.new; p c1; puts c1.object_id'
|#<C:0xb7d921c8>
|-605253404
|
|What id does the object "c1" have - 0xb7d921c8 or -605253404 ?
|If -605253404, why it is negative?

-605253404 (0xb7d921c8 is an "address" of the object).
And it's negative just because object_id is an arbitrary integer
number.

matz.
 
S

Sea&Gull

Yukihiro said:
Hi,

In message "Re: Object id"

|u@l:~> ruby -w -e 'class C; end; c1 = C.new; p c1; puts c1.object_id'
|#<C:0xb7d921c8>
|-605253404
|
|What id does the object "c1" have - 0xb7d921c8 or -605253404 ?
|If -605253404, why it is negative?

-605253404 (0xb7d921c8 is an "address" of the object).
And it's negative just because object_id is an arbitrary integer
number.

matz.

Ok, it's now clear :)
I have not seen in "Programming Ruby" or anywhere else
that object_id can be a negative integer, so I was a bit confused
when saw it myself in experiments with Ruby.
 

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

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top