This project is archived and is in readonly mode.

#4838 ✓committed
Paul Mucur

[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

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

Referenced by

Pages