Last active
August 29, 2015 14:00
-
-
Save thatrubylove/11301224 to your computer and use it in GitHub Desktop.
Open/Closed Example in #Ruby
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
require 'active_support/inflection' | |
Dir["./path/to/broadcasters/*.rb"].each {|broadcaster| require broadcaster } | |
module NewsDigestBroadcaster | |
extend self | |
def broadcast(user, preference) | |
broadcaster = Object.const_get("#{preference.capitalize}NewsDigestBroadcaster") | |
broadcaster.(user, news_digest) | |
end | |
alias_method :call, :broadcast | |
private | |
def news_digest | |
# logic to collect and build the news digest collection | |
end | |
end |
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
module EmailNewsDigestBroadcaster | |
extend self | |
def email(user, news) | |
send_email(user, news) | |
end | |
alias_method :call, :email | |
private | |
def send_email(user, news) | |
# send the email | |
end | |
end |
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
module ImNewsDigestBroadcaster | |
extend self | |
def im(user, news) | |
send_im(user, news) | |
end | |
alias_method :call, :im | |
private | |
def send_im(user, news) | |
# send the instant message | |
end | |
end |
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
module TweetNewsDigestBroadcaster | |
extend self | |
def tweet(user, news) | |
send_tweet(user, news) | |
end | |
alias_method :call, :tweet | |
private | |
def send_tweet(user, news) | |
# send the tweet | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment