Guest User

Untitled

a guest
Feb 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. class String
  2. def scan_then_inject
  3. scan(/\w+=\w+/).inject({}) { |h,opt| kv = opt.split('='); h[kv.first] = kv.last; h }
  4. end
  5.  
  6. def scan_groups_then_inject
  7. scan(/\w+=\w+/).inject({}) { |h,opt| kv = opt.split('='); h[kv.first] = kv.last; h }
  8. end
  9.  
  10. def scan_then_splat_hash
  11. Hash[*scan(/(\w+)=(\w+)/).flatten]
  12. end
  13.  
  14. def split_then_splat_hash
  15. Hash[*split(/&|=/)]
  16. end
  17. end
Add Comment
Please, Sign In to add comment