Last active
August 29, 2015 14:10
-
-
Save KamilLelonek/1cf37b10e9dadf1b7043 to your computer and use it in GitHub Desktop.
GravatarHelper with module_function usage
This file contains hidden or 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
require 'digest/md5' | |
module GravatarHelper | |
module_function | |
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 |
This file contains hidden or 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
[0] (pry) main: 0> user = User.new('[email protected]'); | |
[1] (pry) main: 0> GravatarHelper.gravatar_for_email(user.email) | |
=> 'http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af' | |
[2] (pry) main: 0> user.gravatar | |
=> 'http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af' |
This file contains hidden or 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
class User | |
include GravatarHelper | |
attr_reader :email | |
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