This project is archived and is in readonly mode.
HashWithIndifferentAccess#merge should accept block just like Hash#merge
-
David James
I forgot to mention that HashWithIndifferentAccess 'covers up' the underlying Hash#merge, making it hard to get to the original behavior.
-
David James
My workaround for now will be to using #to_hash to convert to a normal hash. Then I can use Hash#merge.
-
Álvaro Bautista
- Tag changed from activesupport, hashwithindifferentaccess to activesupport, hashwithindifferentaccess, patch
That behaviour could be easily implemented. I wrote a simple patch which provides it.
-
Neeraj Singh
- State changed from new to open
@Alvaro could you please supply a patch for rails3 too?
The patch looks good.
-
Bruno Michel
I've updated the patch for Rails3.
-
José Valim
- Assigned user set to Xavier Noria
-
Álvaro Bautista
Hi
Sorry I haven't had time to update the patch.
It seems that my slight modification works in Rails 3, however it needs to be into another file (as Bruno's patch shows).
-
Xavier Noria
There's a fine point about Hash#merge with block: the block is called only for existing keys in the receiver.
For example, if you execute
h = {:a => 0} g = {:a => 1, :b => 2} h.merge(g) do |key, oldval, newval| p key endyou'll see only
:ais printed.Could you please revise the patch taking that into account?
-
Álvaro Bautista
You're right, I didn't take that into account. Here it is a patch that does.
-
Santiago Pastorino
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino
- State changed from open to stale
-
Lyle Underwood
I'm on Rails 3.0.3 and as far as I can tell the block syntax for ActiveSupport::HashWithIndifferentAccess#merge is not working at all.
irb(main):023:0> a = {"one"=>"aye", "two"=>"bee"} => {"one"=>"aye", "two"=>"bee"} irb(main):024:0> a.merge(a) {|k,v| 1} => {"one"=>1, "two"=>1} irb(main):025:0> b = ActiveSupport::HashWithIndifferentAccess.new("one"=>"aye", "two"=>"bee") => {"one"=>"aye", "two"=>"bee"} irb(main):026:0> b.merge(b) {|k,v| 1} => {"one"=>"aye", "two"=>"bee"}
