Skip to content

Instantly share code, notes, and snippets.

@snuxoll
Created February 13, 2009 14:44
Show Gist options
  • Save snuxoll/63932 to your computer and use it in GitHub Desktop.
Save snuxoll/63932 to your computer and use it in GitHub Desktop.
# 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