Guest User

Untitled

a guest
Feb 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. class String
  2. alias _match match
  3. def match(*args)
  4. m = _match(args.shift)
  5. if m && m.length > 1
  6. meta = (class << m; self; end)
  7. args.each_with_index do |name, index|
  8. meta.send(:define_method, name) { self[index+1] }
  9. end
  10. end
  11. m
  12. end
  13. end
  14.  
  15. m = "12:34:56".match(/(\d+):(\d+):(\d+)/, :hour, :minute, :second)
  16. puts m.hour
  17. puts m.minute
  18. puts m.second
Add Comment
Please, Sign In to add comment