Created
April 13, 2018 18:16
-
-
Save stephancom/bb0e954222afcb130e741f0343fb88bc to your computer and use it in GitHub Desktop.
Obscures an email address with asterisks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# hide email, eg john.doe@gmail.com -> j******o@g*******m | |
def obscure_email(email) | |
midstars = -> (s) { s.length > 2 ? s[0] + '*' * (s.length - 2) + s[-1] : s[0]+'*' } | |
email.split('@').map { |p| midstars.call(p) }.join('@') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment