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.

OrderedHash should not pretend to be an Array

#1782

The ActiveSupport::OrderedHash that comes back from such methods as #group_by looks, in script/console, indistinguishable from an Array, which makes me want to call methods on it like an array, which leads to pain and confusion. Attached is a tiny patch that adds an #inspect method to ActiveSupport::OrderedHash that produces output that looks like this: http://pastie.org/364930 Goal is to make it clear that you're dealing with an OrderedHash, but also to encourage you to think of it as having hash-like rather than array-like indexing.

Reported by Greg Borenstein · January 19th, 2009 @ 07:54 PM

State: committed
Milestone: 2.x
Assigned to: Rick Rick
Importance: none

Activity

  1. Pratik
    Pratik
    • Title changed from [PATCH] OrderedHash should not pretend to be an Array to OrderedHash should not pretend to be an Array

    January 19th, 2009 @ 09:27 PM

  2. Rick
    Rick
    • Tag set to activesupport, patch
    • Assigned user set to Rick

    I'm the one that badgered greg over twitter into submitting this patch :) However, #to_hash isn't working for me for some reason. However, since the hash is ordered in Ruby 1.9, I want to change #inspect to match ruby 1.9's Hash.

    January 20th, 2009 @ 07:05 PM

  3. Repository
    Repository
    • State changed from new to committed

    (from [f4bf318db061daa8c6ebb2b700fd15034e031310]) add an inspect method to OrderedHash to make it clear that it is not a species of Array

    Signed-off-by: Michael Koziarski michael@koziarski.com [#1782 OrderedHash should not pretend to be an Array state:committed] http://github.com/rails/rails/co...

    January 26th, 2009 @ 03:29 AM