Created
March 20, 2014 20:57
-
-
Save thoolihan/9673643 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1 = {a: 1, b: 2} | |
h2 = h1.keep_if{|k,v| k == :a} | |
p h1.inspect # => {a: 1} | |
p h2.inspect # => {a: 1} |
if that's not the desired outcome, easiest fix seems to be:
h2 = h1.clone.keep_if{|k,v| k == :a}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
was thinking this was a bug. however, looking at the documentation for this method, it appears that it is intentional for this to delete keys in the hash of the original hash. Seems like by convention, it should have a "!" at the end of the method name though...