which one is object_id?

Discussion in 'Ruby' started by uncutstone, May 9, 2006.

  1. uncutstone

    uncutstone Guest

    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.
     
    uncutstone, May 9, 2006
    #1
    1. Advertising

  2. 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
     
    Robert Klemme, May 9, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hank Gong
    Replies:
    6
    Views:
    120
    Eero Saynatkari
    Dec 21, 2005
  2. Peña, Botp

    get info from object_id

    Peña, Botp, May 31, 2007, in forum: Ruby
    Replies:
    4
    Views:
    140
    Peña, Botp
    Jun 1, 2007
  3. Meinrad Recheis
    Replies:
    5
    Views:
    140
  4. SpringFlowers AutumnMoon

    object_id 1, 2, 3

    SpringFlowers AutumnMoon, Sep 25, 2007, in forum: Ruby
    Replies:
    13
    Views:
    246
    Eric Hodel
    Sep 27, 2007
  5. Evan Moseman

    Get Variable Name from object_id

    Evan Moseman, Jan 12, 2008, in forum: Ruby
    Replies:
    3
    Views:
    148
Loading...

Share This Page