Kavincat Kavincat - 6 months ago 69
Ruby Question

How do I convert MAC address to formatted MAC address

Input: 009CFAEEB779


I was searching for the method but didn't find. Is there any method? or I need to loop(map) through it and add the colon.


Do more research before posting on SO and don't include Rails tags unless the problem relates to web programming using Rails methods.

arr = "009CFAEEB779".scan(/\w{2}/)
=> ["00", "9C", "FA", "EE", "B7", "79"]
=> "00:9C:FA:EE:B7:79"

or shorter

=> "00:9C:FA:EE:B7:79"