This project is archived and is in readonly mode.

#4875 ✓resolved
Chris Griego

OrderedHash#invert returns an unordered hash

Reported by Chris Griego | June 16th, 2010 @ 08:36 PM | in 3.0.2

ActiveSupport::OrderedHash#invert will return an hash of indeterminate order, which is inconsistent with Ruby 1.9.

>> a = {"foo" => "FOO", "bar" => "BAR", "baz" => "BAZ"}
=> {"baz"=>"BAZ", "foo"=>"FOO", "bar"=>"BAR"}
>> b = ActiveSupport::OrderedHash[[["foo", "FOO"], ["bar", "BAR"], ["baz", "BAZ"]]]
=> #<OrderedHash {"baz"=>"BAZ", "foo"=>"FOO", "bar"=>"BAR"}>
>> a.keys
=> ["baz", "foo", "bar"]
>> b.keys
=> ["foo", "bar", "baz"]
>> a.invert
=> {"BAZ"=>"baz", "FOO"=>"foo", "BAR"=>"bar"}
>> b.invert
=> {"BAZ"=>"baz", "FOO"=>"foo", "BAR"=>"bar"}
>> a.invert.invert
=> {"baz"=>"BAZ", "foo"=>"FOO", "bar"=>"BAR"}
>> b.invert.invert
=> {"baz"=>"BAZ", "foo"=>"FOO", "bar"=>"BAR"}

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>


Referenced by