Created
February 10, 2010 20:55
-
-
Save leandro/300826 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # recursive Hash#clone extension, because I needed it! | |
| class Hash | |
| def clone(recursive = false) | |
| return super() unless recursive | |
| new_hash = {} | |
| for k, v in self | |
| key = k.is_a?(Hash) ? k.clone(true) : (k.clone rescue k) | |
| value = v.is_a?(Hash) ? v.clone(true) : (v.clone rescue v) | |
| new_hash[key] = value | |
| end | |
| new_hash | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment