I’m in the middle of Ruby Under a Microscope by Pat Shaughnessy. I love the book so far, and I will certainly post a more specific review and recommendation soon, but I just noticed a real semantic difference between Ruby and C# that I wanted to blog about, because it would certainly have tripped me up if I had stumbled across it in production code. From Shaughnessy’s chapter on hash tables:
In the case of strings and arrays, Ruby actually iterates through all the characters in the string or the elements in the array and calculates a cumulative hash value (p. 183)
“That’s weird,” I thought, “I bet that means that it’s not safe to use arrays as hash table keys in Ruby. So I did an experiment: