TL; DR - 它是用於Ruby的top-level對象hash
值,相當於self.hash
。
這裏有一個小的調試幫助:
irb(main):001:0> hash
#=> 3220857809431415791
irb(main):002:0> defined? hash
#=> "method"
irb(main):003:0> method(:hash)
#=> #<Method: Object(Kernel)#hash>
現在,您可以查找Object#hash
在線:
http://ruby-doc.org/core-2.3.1/Object.html#method-i-hash
或者在IRB:
irb(main):004:0> help "Object#hash"
= Object#hash
(from ruby core)
------------------------------------------------------------------------------
obj.hash -> fixnum
------------------------------------------------------------------------------
Generates a Fixnum hash value for this object. This function must have the
property that a.eql?(b) implies a.hash == b.hash.
The hash value is used along with #eql? by the Hash class to determine if two
objects reference the same hash key. Any hash value that exceeds the capacity
of a Fixnum will be truncated before being used.
The hash value for an object may not be identical across invocations or
implementations of Ruby. If you need a stable identifier across Ruby
invocations and implementations you will need to generate one with a custom
method.
#=> nil
irb(main):005:0>
Object(Kernel)#hash
實際上意味着hash
在Kernel
定義,但如文檔中所述的用於Object
:
雖然對象的實例方法是由內核模塊定義,我們選擇來記錄他們這裏爲了清楚。
http://ruby-doc.org/core-2.0.0/Object.html#method-i-hash – mudasobwa