ordered snippets

How to use ActiveRecord::OrderedHash

Tagged ordered, hash, rails, activesupport  Languages ruby

Ruby 1.8 doesn't retain the order of objects inserted in to a hash, but with ActiveSupport::OrderedHash you can do this:

a=ActiveSupport::OrderedHash[:one, 1, :two, 2]

which gives you:

=> #<OrderedHash {:one=>1, :two=>2}>