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

Rename keys in-place to avoid assigning nil. #12

Merged
merged 1 commit into from
Mar 18, 2018
Merged

Conversation

nickcharlton
Copy link
Owner

Some attributes on initial creation have different names when updating
an existing resource. Previously, we were assigning regardless of
whether or not a value in the collection existed, which meant that often
we'd pass nil on submission.

This avoids doing that by renaming the key if it exists instead.

end

def replace_key!(original, replacement)
return self if self[original] == nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer the use of the nil? predicate.

Repository owner deleted a comment from houndci-bot Mar 18, 2018
Repository owner deleted a comment from houndci-bot Mar 18, 2018
Repository owner deleted a comment from houndci-bot Mar 18, 2018
Some attributes on initial creation have different names when updating
an existing resource. Previously, we were assigning regardless of
whether or not a value in the collection existed, which meant that often
we'd pass `nil` on submission.

This avoids doing that by renaming the key if it exists instead.
Repository owner deleted a comment from houndci-bot Mar 18, 2018
Repository owner deleted a comment from houndci-bot Mar 18, 2018
Repository owner deleted a comment from houndci-bot Mar 18, 2018
Repository owner deleted a comment from houndci-bot Mar 18, 2018
Repository owner deleted a comment from houndci-bot Mar 18, 2018
Repository owner deleted a comment from houndci-bot Mar 18, 2018
Repository owner deleted a comment from houndci-bot Mar 18, 2018
Repository owner deleted a comment from houndci-bot Mar 18, 2018
Repository owner deleted a comment from houndci-bot Mar 18, 2018
Repository owner deleted a comment from houndci-bot Mar 18, 2018
Repository owner deleted a comment from houndci-bot Mar 18, 2018
Repository owner deleted a comment from houndci-bot Mar 18, 2018
@nickcharlton nickcharlton merged commit 6298340 into master Mar 18, 2018
@nickcharlton nickcharlton deleted the rename-key branch March 18, 2018 20:47
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.

None yet

2 participants