This script shows ruby 1.8.7's strange behavior relating to the order of a returned array after setting certain unrelated hashes.
a = { :a => nil }
running this code first causes the below to return in reverse order.
b = { :a => nil }
running this code first causes the below to return in correct order.
{ :y => true, :s => true }.collect { |k, v| k }
is the code that returns the array. It is run the same way every iteration.
For this bug to manifest, irb must be restarted between tests. Once an irb session has returned the array in a particular direction, it will continue to return it in that direction no matter what is done until you exit and restart irb. (Thus, this bash script to automate starting and using irb.) This bug does not happen in ruby 1.9.3, meaning no matter what you do, you will always get the array returned in the same direction. The results are repeatably reliable.
The test_ruby_bug.txt file is the output of this script.