Cares about PANs (Primary Account Number).
require'pan'pan='1234567890123456'Pan.mask(pan)#=> '123456******3456'pan#=> '1234567890123456'Pan.truncate(pan)#=> '123456******3456'pan#=> '123456******3456'(Yes, that's the difference between masking and truncating a PAN in PCI DSS terminology.)
You may decide how much to mask (or truncate) and the character(s) that the digits are replaced with:
Pan.template=[0,'x',4]Pan.mask('1234567890123456')#=> 'xxxxxxxxxxxx3456'pan='1234567890123456'Pan.mask(pan,template: [4,'X',4])#=> '1234XXXXXXXX3456'Pan.truncate(pan,template: [6,'*',4]);pan#=> '123456******3456'