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
merged 4 commits into from
Jul 17, 2017

Conversation

Erol
Copy link
Contributor

@Erol Erol commented Feb 20, 2017

Summary

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

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

indifferent_ab = HashWithIndifferentAccess.new(a: 1, b: 2)
indifferent_c = HashWithIndifferentAccess.new(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}

@rails-bot
Copy link

r? @sgrif

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

@al2o3cr
Copy link
Contributor

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.

@Erol
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
@Erol
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
@Erol
Copy link
Contributor Author

Erol commented Mar 15, 2017

Hi @maclover7, anyone I can consult this with?

@Erol
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
@Erol
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
See: https://guides.rubyonrails.org/5_2_release_notes.html

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

* Update Gemfile.next.lock

* Update Gemfile.next.lock

* updating changes?/attribute_changed? behavior for after_save callbacks

https://www.fastruby.io/blog/rails/upgrades/active-record-5-1-api-changes.html

* 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 <campbell.allen@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants