Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the order of Hash#reverse_merge! consistent with HashWithIndifferentAccess #28077

merged 4 commits into from Jul 17, 2017


Copy link

@Erol Erol commented Feb 20, 2017


Currently, the result of Hash#reverse_merge! deviates from the ordering of similar methods:

ab = {a: 1, b: 2}
c = {c: 3}

indifferent_ab = 1, b: 2)
indifferent_c = 3)

ab.reverse_merge(c) #=> {c: 3, a: 1, b: 2}
ab.reverse_merge!(c) #=> {a: 1, b: 2, c: 3}
indifferent_ab.reverse_merge(c) #=> {c: 3, a: 1, b: 2}
indifferent_ab.reverse_merge!(c) #=> {c: 3, a: 1, b: 2}

This PR aims to make the element order consistent across the 4 methods such that:

ab.reverse_merge!(c) #=> {c: 3, a: 1, b: 2}

Copy link

r? @sgrif

(@rails-bot has picked a reviewer for you, use r? to override)

Copy link

al2o3cr commented Feb 20, 2017

Probably not a concern in any realistic use cases for this function, but this change does make an extra copy of the original Hash compared to the previous implementation.

Copy link
Contributor Author

Erol commented Feb 20, 2017

That's true. What I also haven't done yet is run a benchmark to see the impact.

It does make the implementation simpler to maintain, since it's the same as HashWithIndifferentAccess:

A further improvement could be to remove the method definition there, since it inherits from Hash.

@Erol Erol force-pushed the make-reverse-merge-bang-order-consistent branch 2 times, most recently from 45c91d2 to d5b590d Compare February 21, 2017 06:01
Copy link
Contributor Author

Erol commented Mar 3, 2017

What do you think of this change @sgrif?

@Erol Erol force-pushed the make-reverse-merge-bang-order-consistent branch from 20bb336 to e505bc8 Compare March 6, 2017 07:35
Copy link
Contributor Author

Erol commented Mar 15, 2017

Hi @maclover7, anyone I can consult this with?

Copy link
Contributor Author

Erol commented Apr 9, 2017

Hi @rafaelfranca just wanted to consult with you about this change. If this is something that can be merged, I can have the PR rebased

@sgrif sgrif merged commit 3bda7ff into rails:master Jul 17, 2017
@Erol Erol deleted the make-reverse-merge-bang-order-consistent branch July 19, 2017 04:52
Copy link
Contributor Author

Erol commented Jul 19, 2017

Just saw this, thanks @sgrif

yuenmichelle1 added a commit to zooniverse/panoptes that referenced this pull request Nov 15, 2022
…?/attribute_changed? for after_save callbacks. (#4000)

* update classification.rb in rails 5.2 Hash#reverse_merge! behavior changes

See rails/rails#28077

* update updatable_resource.rb to replace deprecated changed? to saved_changes?

* Update

* Update

* updating changes?/attribute_changed? behavior for after_save callbacks

* revert saved_changes? to changed? in updatable resource. only use saved_changes? for after_save callbacks

* hound sniff update user.rb set_zooniverse_id if clause to single  line

* add spec to test if the missing email_communication field is set correctly

* always modify the resource updated_at when updating links

* update find_or_create to use more readable has_changes_to_save as opposed to changed?

(incorrectly used saved_changes? on initial fix)

* simplify assignment to upp.email_communication on find_or_create.rb

* update find_or_create_spec.rb spec that checks if email_communication is set

Co-authored-by: Campbell Allen <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging this pull request may close these issues.

None yet

5 participants