Array.to_ordered_hash replacement for Rails 2.3

The simple [[1,2]]

does no longer work in Rails 2.3, so I built a small patch for array that make OrderedHash creation simple again.


class Array
  def to_ordered_hash


hash = [[:key, 'value'], [:key2, :value2], [1, 2]].to_ordered_hash
hash == {:key=>'value', :key2=>:value2, :1=>2}

a more complete but longer/harder version

8 thoughts on “Array.to_ordered_hash replacement for Rails 2.3

  1. Thanks for this tip! I was very confused when I tried to instantiate a new hash with the same way I had done before only to get back an empty hash! Adding Array#to_ordered_hash makes instantiation so much nicer. I wish they would add that to core Ruby or Rails.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s