[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Object id

Sea&Gull

1/19/2005 3:48:00 PM

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!

--
s&g
2 Answers

Yukihiro Matsumoto

1/19/2005 5:04:00 PM

0

Hi,

In message "Re: Object id"
on Thu, 20 Jan 2005 00:51:19 +0900, Sea&Gull <v@vsu.ru> writes:

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


Sea&Gull

1/19/2005 5:26:00 PM

0

Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: Object id"
> on Thu, 20 Jan 2005 00:51:19 +0900, Sea&Gull <v@vsu.ru> writes:
>
> |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.