I'm just a newbie to ruby. I've seen a string method (String).hash .
For example, in irb, I've tried
>> "mgpyone".hash
returns
=> 144611910
how does this method works ?
I'm just a newbie to ruby. I've seen a string method (String).hash .
For example, in irb, I've tried
>> "mgpyone".hash
returns
=> 144611910
how does this method works ?
The hash method is defined for all objects. See documentation:
Generates a
Fixnumhash value for this object. This function must have the property thata.eql?(b)impliesa.hash == b.hash. The hash value is used by classHash. Any hash value that exceeds the capacity of aFixnumwill be truncated before being used.
So the String.hash method is defined in C-Code. Basically (over-simplified) it just sums up the characters in that string.