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

Implement non-destructive standard Hash methods #481

Merged

Conversation

BobbyMcWho
Copy link
Collaborator

Resolves #480

When calling the following non-destructive hash methods:

:compact
:invert
:reject
:select
:slice
:transform_keys
:transform_values

we would be returned an instance of a standard Hash rather
than a Mash (or subclass). This changes that behavior to
instead return an instance of the class the method was
called on.

Also, as of ruby 2.6, Hash#merge and Hash#merge! allow for multiple hashes
to be passed to the method, and will merge each one in the order that
they were passed. I implemented that in this PR as well, but I could always pull it out into a separate PR if @dblock or @michaelherold think it's necessary to do so.

Ideally this is merged before #479, and I can remove a little scope from that one to specifically target the Rails method it was intended to fix.

Do these changes warrant a major bump since they change the returned type for those methods? I'm not sure returning a Mash instead of a standard Hash would be considered breaking in most cases, but I'm open to thoughts.

@BobbyMcWho BobbyMcWho force-pushed the 480-implement-non-destructive-methods branch 3 times, most recently from 4eaa260 to 9d77668 Compare August 14, 2019 04:50
@dblock
Copy link
Member

dblock commented Aug 14, 2019

I merged #482, rebase and stuff. Will CR, thanks!

When calling the following non-destructive hash methods:
:compact
:invert
:reject
:select
:slice
:transform_keys
:transform_values
we would be returned an instance of a standard Hash rather
than a Mash (or subclass). This changes that behavior to
instead return an instance of the class the method was
called on.
As of ruby 2.6, Hash#merge and Hash#merge! allow for multiple hashes
to be passed to the method, and will merge each one in the order that
they were passed.
@BobbyMcWho BobbyMcWho force-pushed the 480-implement-non-destructive-methods branch from 9d77668 to 157c3ec Compare August 14, 2019 16:31
@BobbyMcWho
Copy link
Collaborator Author

@dblock This has been rebased, and is ready for CR 😸

@dblock
Copy link
Member

dblock commented Aug 16, 2019

I like this a lot. You should update README, CHANGELOG and UPGRADING. I'll be ok with merging this if @michaelherold is ok.

@michaelherold
Copy link
Member

This looks good to me! Thanks for catching these issues.

@BobbyMcWho
Copy link
Collaborator Author

BobbyMcWho commented Aug 16, 2019

Can you give me some guidance on the most appropriate place in the changelog for this?

Edit: I'm leaning changed, but that would make this a major version bump

@michaelherold
Copy link
Member

Yeah, it would really be "changed" since these methods were previously returning a different data type. However, given that that feels like a bug, it could also be considered for "fixed".

@BobbyMcWho
Copy link
Collaborator Author

I would argue for Fixed if it was just the Ruby version specific methods that needed fixed and we were quick about fixing them post-release, but given how long the current behavior has acted this way, I'd argue that at this point it's safest for everyone to just go with a Major version bump

@dblock
Copy link
Member

dblock commented Aug 18, 2019

I am +1 on major version bump. it's the safest.

@dblock dblock merged commit 04cd30a into hashie:master Aug 18, 2019
@dblock
Copy link
Member

dblock commented Aug 18, 2019

I merged this.

@dblock dblock mentioned this pull request Aug 18, 2019
BobbyMcWho added a commit to BobbyMcWho/hashie that referenced this pull request Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hashie behavior when calling Hash methods that return a new Hash
3 participants