Skip to content

Instantly share code, notes, and snippets.

@titanous
Created June 8, 2010 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save titanous/430430 to your computer and use it in GitHub Desktop.
Save titanous/430430 to your computer and use it in GitHub Desktop.
def mask n;n[0,6]+'*'*(n.size-10)+n[-4,4]end
@pritchie
Copy link

pritchie commented Jun 9, 2010

But what about strings smaller than 10 characters?

http://gist.github.com/430895

@titanous
Copy link
Author

titanous commented Jun 9, 2010

This is an entry to the Braintree RailsConf Code Golf competition[1]. Credit Card numbers aren't shorter than 10 characters[2].

1 http://codegolf.getbraintree.com/
2 http://en.wikipedia.org/wiki/Bank_card_number#IIN_Ranges_Allocated_to_Issuing_Networks

@pritchie
Copy link

pritchie commented Jun 9, 2010

Ouch, in that case all that checking is quite sub-optimal then isn't it?

How about: http://gist.github.com/431442 ?

@titanous
Copy link
Author

titanous commented Jun 9, 2010

Very nicely done.

@pritchie
Copy link

pritchie commented Jun 9, 2010

Thanks, working on that was a great way to wake myself up this morning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment