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

Remapeio de chaves do hash #4

Merged
merged 7 commits into from
Apr 28, 2015

Conversation

darthjee
Copy link
Contributor

This PR creates a method to remap the keys of a hash

{ a:1, b: 2 }.remap_keys(a: :e, c: :g)
{ e: 1, b: 2, g: nil }

@darthjee darthjee changed the title Remapeio de chaves com argumento hash Remapeio de chaves do hash Apr 22, 2015
@darthjee darthjee mentioned this pull request Apr 22, 2015
4 tasks
@@ -18,6 +18,12 @@ def squash
end
end

def remap_keys(remap)
change_keys do |key|
remap.key?(key) ? remap[key] : key

Choose a reason for hiding this comment

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

the performance would not be better iterating over remap instead of change_keys?

@tadeusrox
Copy link

what happen when

{ a: 1, b: 2 }.remap_keys{ a: :b, b: :c }

@darthjee
Copy link
Contributor Author

Good question. by the logic, we should get:

{ b: 1, c:2 }

I'll add an spec and if necessary, correct the code

@tadeusrox
Copy link

:shipit:

darthjee added a commit that referenced this pull request Apr 28, 2015
@darthjee darthjee merged commit 4bf36fc into ff-hash-exclusive-merge-TRD-250 Apr 28, 2015
@darthjee darthjee deleted the ff-hash-remap-TRD-250 branch April 28, 2015 23:38
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

3 participants