Created
February 13, 2009 14:44
-
-
Save snuxoll/63932 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
# Create a new hash and extend it with our CollectKeyValue | |
# module | |
hash ={ | |
"key_1"=>"one", | |
"key_2"=>"two", | |
"key_3"=>"three", | |
"key_4"=>"four" | |
}.extend(CollectKeyValue) | |
# Now lets call our new hash#collect_kv method and rename | |
# "key" in the keys to "fish" (because we can!) | |
new_hash = hash.collect_kv do | key, value | | |
new_key = key.gsub(/key/, "fish") | |
[new_key, value] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment