Last active
October 2, 2015 02:47
-
-
Save ipoval/2154846 to your computer and use it in GitHub Desktop.
DP: Fabric Class
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
class Blog | |
attr_writer :post_source | |
def new_post | |
post_source.call.tap do |p| | |
p.blog = self | |
end | |
end | |
private | |
## | |
## fabric pattern | |
## | |
def post_source | |
@post_source ||= Post.public_method(:new) | |
end | |
end | |
class Post | |
## | |
## dependency injection pattern | |
## | |
def publish(clock = DateTime) | |
self.pubdate = clock.now blog.add_entry(self) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment