How does the .hash string method work?

I'm just new to ruby. I saw the string method (String) .hash.

For example, in irbI tried

>> "mgpyone".hash

returns

=> 144611910

how does this method work?

+5
source share
1 answer

The method is hashdefined for all objects. See documentation :

Creates a hash value Fixnumfor this object. This function must have the property a.eql?(b)attracts a.hash == b.hash. The hash value is used by the class hash. Any hash value that exceeds the capacity of a is Fixnumtruncated before use.

, String.hash C-Code. () .

+9

All Articles