Where is the #hash method defined?

Discussion in 'Ruby' started by Iñaki Baz Castillo, Jun 8, 2011.

  1. Hi, any object in Ruby has the method #hash which returns an integer
    unique for the object (such value doesn't change during the lifetime
    of the Ruby process).

    I cannot find which class or module #hash method belongs to. I
    expected it could be in Object class, but it's not. Where is it?

    Thanks a lot.


    --=20
    I=C3=B1aki Baz Castillo
    <>
     
    Iñaki Baz Castillo, Jun 8, 2011
    #1
    1. Advertisements

  2. I cannot find which class or module #hash method belongs to. I
    method:)hash).owner # => Kernel

    I think the above tip was discussed on the list sometime back.
     
    Anurag Priyam, Jun 8, 2011
    #2
    1. Advertisements

  3. Thanks, I didn't know the #owner method :)

    It's strange that the #hash method is not defined within the Kernel doc:

    http://www.ruby-doc.org/core/classes/Kernel.html

    --=20
    I=C3=B1aki Baz Castillo
    <>
     
    Iñaki Baz Castillo, Jun 9, 2011
    #3
  4. Iñaki Baz Castillo

    Ryan Davis Guest

    % ri hash
    ...
    (from ruby core)
    =3D=3D=3D Implementation from Object
    =
    --------------------------------------------------------------------------=
    ----
    obj.hash =3D> fixnum

    =
    --------------------------------------------------------------------------=
    ----

    Generates a Fixnum hash value for this object. This function must have =
    the
    property that a.eql?(b) implies a.hash =3D=3D b.hash. The hash value is =
    used by
    class Hash. Any hash value that exceeds the capacity of a Fixnum will be
    truncated before being used.
    ...
     
    Ryan Davis, Jun 9, 2011
    #4

  5. Thanks a lot. However it's not documented in Object class rdoc:

    http://www.ruby-doc.org/core/classes/Object.html

    a bug in the doc?

    --=20
    I=C3=B1aki Baz Castillo
    <>
     
    Iñaki Baz Castillo, Jun 9, 2011
    #5

  6. Thanks for the very good explanation.

    I see. Ok. Thanks a lot.

    --=20
    I=C3=B1aki Baz Castillo
    <>
     
    Iñaki Baz Castillo, Jun 9, 2011
    #6
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.