Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Add first and last to OrderedHash

#2463

When we upgraded our app from 2.1 to 2.3 the change in OrderedHash to be based on a hash rather than an array broke some of our code.

This patch adds first and last back onto the ordered hash - just for convenience's sake.

Reported by John · April 9th, 2009 @ 04:36 AM

State: wontfix
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. James
    James

    Very handy indeed. Good to get this functionality back.

    April 9th, 2009 @ 05:39 AM

  2. Brian Hogan
    Brian Hogan

    +1 just because of uniformity. Like .each or .collect.

    April 9th, 2009 @ 06:44 AM

  3. Gareth Adams
    Gareth Adams

    This is a useful patch, +1

    I was planning to open a bug report about OrderedHash#to_a not returning ordered results, maybe this is a better place for it?

    April 15th, 2009 @ 08:58 AM

  4. John
    John

    I can add this to the patch if you like?

    April 15th, 2009 @ 09:00 AM

  5. John
    John

    and now an ordered to_a method is included as well

    April 16th, 2009 @ 12:28 AM

  6. John
    John
    • Tag set to verified

    April 16th, 2009 @ 12:29 AM

  7. John
    John

    hey just pinging this ticket, it's been tagged verified for near a month

    May 12th, 2009 @ 01:48 AM

  8. David Trasbo
    David Trasbo
    • Assigned user set to Ryan Bigg

    Regular hashes are ordered in Ruby 1.9, so I think this ticket should be marked as "won't fix" - in my opinion it serves no purpose to keep maintaining a piece of functionality that is available in newer versions of Ruby by default.

    If people want OrderedHash to behave differently they can patch it on a per-app basis - or just upgrade.

    April 14th, 2010 @ 07:40 PM

  9. Ryan Bigg
    Ryan Bigg
    • State changed from new to verified
    • Assigned user cleared.

    If 3 people want a ticket it should be made into Rails unless Core vetos it. NOT marking as invalid, but rather verified so it should get some eyes.

    April 15th, 2010 @ 11:03 AM

  10. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  11. Rizwan Reza
    Rizwan Reza
    • Tag changed from verified to bugmash-review

    The patch didn't apply cleanly and also implemented to_a.

    The patch attach applies cleanly, passes all tests and only implements first and last, as there is an implementation of to_a there now.

    May 16th, 2010 @ 07:30 PM

  12. Rizwan Reza
    Rizwan Reza
    • Tag cleared.
    • State changed from verified to wontfix

    José replied:

    OrderedHash behaves like a Hash now to be more close to Ruby 1.9 behavior. Since 1.9 we don't have #first and #last, OrderedHash shouldn't as well.

    May 16th, 2010 @ 07:39 PM