Rails Hash Ordering
My expectation was that when I create a hash it’s going to act like a queue and be sorted in the order in which I inserted things. As I found out today, that is definitely not the case.
There is a very easy way that Rails offers to give a hash this behavior and it’s the OrderedHash function found in the ActiveSupport libraries.
my_hash = ActiveSupport::OrderedHash.new
After that initialization, your hash will be maintained in the order you insert things. Something to watch out for.
Commenting has expired for this post.