Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Last active August 29, 2015 14:10
Show Gist options
  • Save KamilLelonek/af7300d6c880bbd17a2b to your computer and use it in GitHub Desktop.
Save KamilLelonek/af7300d6c880bbd17a2b to your computer and use it in GitHub Desktop.
GravatarHelper module to be mixed in any class
require 'digest/md5'
module GravatarHelper
def gravatar_for_email(email)
"#{gravatar_endpoint}#{hash_for_email(email)}"
end
def hash_for_email(email)
Digest::MD5.hexdigest(email)
end
def gravatar_endpoint
'http://www.gravatar.com/avatar/'
end
end
[0] (pry) main: 0> puts User.new('[email protected]').gravatar
=> 'http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af'
class User
include GravatarHelper
def initialize(email)
@email = email
end
def gravatar
gravatar_for_email @email
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment