which one is object_id?

U

uncutstone

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

Robert Klemme

uncutstone said:
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
 

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
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top