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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The results of these expressions are not all the same data. Ruby 1.8 integers contain character numbers for single character indexing. This has been changed in Ruby 1.9, but
slice(0)returns the first character of the string'@', not'a'.In Ruby 1.8 (using
irb):In Ruby 1.9.1: