Ruby: How come the same strings have different hashcodes?

Posted by they changed my name on Stack Overflow See other posts from Stack Overflow or by they changed my name
Published on 2010-04-22T01:36:57Z Indexed on 2010/04/22 1:43 UTC
Read the original article Hit count: 195

Filed under:
|
test = 'a'
test2 = '@a'.slice(0)
test3 = '@a'[1]

puts test.hash
puts test2.hash
puts test3.hash

Output:

100
64
97

Is this a bug or am I misunderstanding how the hash method works? Is there a way to fix this?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about hash