Guest User

Untitled

a guest
Jul 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. # Module containing a collect_kv method to allow
  2. # a new hash to be generated my collect instead
  3. # of returning an array of modified keys or values
  4. module CollectKeyValue
  5.  
  6. # Takes a block that returns a [key, value] pair
  7. # and builds a new hash based on those pairs
  8. def collect_kv
  9. result = {}
  10. each do |k,v|
  11. new_k, new_v = yield k, v
  12. result[new_k] = new_v
  13. end
  14. result
  15. end
  16.  
  17. end
Add Comment
Please, Sign In to add comment