This project is archived and is in readonly mode.

#5390 ✓stale
Ronny Haryanto

ActiveSupport::OrderedHash merge does not maintain order

Reported by Ronny Haryanto | August 17th, 2010 @ 07:00 AM

>> a = ActiveSupport::OrderedHash[9, 2, 3, 1]
=> #<OrderedHash {3=>1, 9=>2}>
>> b = ActiveSupport::OrderedHash[7, 4]
=> #<OrderedHash {7=>4}>
>> c = b.merge(a)
=> #<OrderedHash {7=>4, 3=>1, 9=>2}>

Expected c to be {3=>1, 7=>4, 9=>2}. Is this by design?

Comments and changes to this ticket

  • Ronny Haryanto

    Ronny Haryanto August 17th, 2010 @ 07:01 AM

    • Tag changed from activesupport orderedhash to 2.3.5, activesupport, orderedhash
  • Ronny Haryanto

    Ronny Haryanto August 17th, 2010 @ 07:02 AM

    Forgot to mention version: 2.3.5. Ruby 1.8.7.

  • Dimitar P. Dimitrov

    Dimitar P. Dimitrov November 16th, 2010 @ 01:24 PM

    The ActiveSupport::OrderedHash#inspect method is defined as follows in Rails 2.3.5:

    def inspect
      "#<OrderedHash #{super}>"
    end
    

    Therefore, the result of #inspect shouldn't be used to demonstrate how the hash is ordered. Please update your ticket report and use the #keys method, for example, to monitor the ordering of the keys.

    Moreover, I think that this initialization ActiveSupport::OrderedHash[9, 2, 3, 1] should produce the ordered hash @{ 9 => 2, 3 => 1 }@, not { 3 => 1, 9 => 2 } as is in your example.

  • rails

    rails February 18th, 2011 @ 12:00 AM

    • State changed from “new” to “open”
    • Tag changed from 2.3.5, activesupport, orderedhash to 235, activesupport, orderedhash

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • rails

    rails February 18th, 2011 @ 12:00 AM

    • State changed from “open” to “stale”
  • bingbing

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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages