Skip to content

Instantly share code, notes, and snippets.

@stephancom
Created April 13, 2018 18:16
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 stephancom/bb0e954222afcb130e741f0343fb88bc to your computer and use it in GitHub Desktop.
Save stephancom/bb0e954222afcb130e741f0343fb88bc to your computer and use it in GitHub Desktop.
Obscures an email address with asterisks
# 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