[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

which one is object_id?

uncutstone

5/9/2006 12:25:00 AM

I got different object_id from different method call, please see the
code below

a = Myclass.new("mike")
p a
p a.to_s
p a.object_id


Following is result:

#<Myclass:0x27a9584 @name="mike">
"#<Myclass:0x27a9584>"
20794050

Acctually hexadecimal 0x27a9584 is 2 times of decimal 20794050.

What this means? which one is the real object_id?

Thanks.

1 Answer

Robert Klemme

5/9/2006 7:30:00 AM

0

uncutstone wrote:
> I got different object_id from different method call, please see the
> code below
>
> a = Myclass.new("mike")
> p a
> p a.to_s
> p a.object_id
>
>
> Following is result:
>
> #<Myclass:0x27a9584 @name="mike">
> "#<Myclass:0x27a9584>"
> 20794050
>
> Acctually hexadecimal 0x27a9584 is 2 times of decimal 20794050.
>
> What this means? which one is the real object_id?

The one returned by #object_id. #to_s has nothing to do with object ids:

>> a=%[aaa bb ccc]
=> "aaa bb ccc"
>> a.to_s
=> "aaa bb ccc"
>> a.object_id
=> 2061076

Implementation wise there are some connections but that's irrelevant for
your question.

Cheers

robert