This project is archived and is in readonly mode.
[PATCH] Add Block Support to ActiveSupport OrderedHash merge
Reported by Paul Mucur | June 12th, 2010 @ 12:15 AM
ActiveSupport's OrderedHash
's implementation of
merge
and merge!
does not support passing
a block as per the standard library (c.f. http://ruby-doc.org/core/classes/Hash.html#M002880
)
The attached patch adds support to match the standard library's method signature:
hsh.merge(other_hash){|key, oldval, newval| block} → a_hash
Tests are also included.
This makes it possible to effectively map over an OrderedHash without turning it into an array by merging it with itself:
a = ActiveSupport::OrderedHash.new
a["age"] = 1
a["height"] = 15
a.merge(a) { |k, v| v * 2 }
# => #<OrderedHash {"height"=>30, "age"=>2}>
Comments and changes to this ticket
-
Paul Barry June 12th, 2010 @ 04:29 AM
This looks good. I've attached a patch that re-organizes the test for merge into a few smaller tests.
-
Repository June 13th, 2010 @ 03:19 AM
- State changed from new to committed
(from [58e21a4a0d4eefc395139e88c1f184b9eaf0b4c4]) Support passing a block to ActiveSupport::OrderedHash's merge and merge! [#4838 state:committed]
For better consistency with Ruby's own Hash implementation.
Signed-off-by: Xavier Noria fxn@hashref.com
http://github.com/rails/rails/commit/58e21a4a0d4eefc395139e88c1f184...
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
Referenced by
- 4838 [PATCH] Add Block Support to ActiveSupport OrderedHash merge (from [58e21a4a0d4eefc395139e88c1f184b9eaf0b4c4]) Support...