Guest User

Untitled

a guest
Jan 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. mac="0800273B51A9"
  2.  
  3. # With reject
  4. mac.split(/(..)/).reject {|c| c.empty?}.join(':')
  5.  
  6.  
  7. # With Inject
  8. mac.split(//).inject([]) do |nmac, e|
  9. if x.nil? or x>0
  10. nmac[nmac.size-1] = nmac[nmac.size-1] + e
  11. x=0
  12. else
  13. nmac[nmac.size] = e
  14. x=x+1
  15. end
  16. nmac
  17. end.join(':')
  18.  
  19. mac.split(//).inject([]) { |m, e| if x.nil? or x>0 ;
  20. m[m.size-1] = m[m.size-1] + e ; x=0 ; else ; m[m.size] = e ;
  21. x=x+1 ; end ; m }.join(':')
Add Comment
Please, Sign In to add comment