Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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
Add Comment
Please, Sign In to add comment