-
-
Save bullfight/824721 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
# Module containing a collect_kv method to allow | |
# a new hash to be generated my collect instead | |
# of returning an array of modified keys or values | |
module CollectKeyValue | |
# Takes a block that returns a [key, value] pair | |
# and builds a new hash based on those pairs | |
def collect_kv | |
result = {} | |
each do |k,v| | |
new_k, new_v = yield k, v | |
result[new_k] = new_v | |
end | |
result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment