This project is archived and is in readonly mode.

#6364 ✓resolved
ghorner

[PATCH] ActiveSupport::OrderedHash#each* methods don't return self

Reported by ghorner | February 2nd, 2011 @ 03:21 PM

I noticed while using Enumerable#group_by that ordered hashes don't act like normal hashes. Specifically, their each* methods return their keys instead of self:

>> h = ActiveSupport::OrderedHash.new.merge :a =>1, :b =>2
=> #<OrderedHash {:a=>1, :b=>2}>
>> h.each { }
=> [:a, :b]
>> h.each_key { }
=> [:a, :b]
>> h.each_value { }
=> [:a, :b]

Breaking compatibility with Hash is not good as it leads to unexpected and broken behavior. It also seems these methods were made with the intention of Hash compatibility.

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

People watching this ticket

Attachments

Tags

Referenced by

Pages