Skip to content

Instantly share code, notes, and snippets.

@ipoval
Last active October 2, 2015 02:47
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 ipoval/2154846 to your computer and use it in GitHub Desktop.
Save ipoval/2154846 to your computer and use it in GitHub Desktop.
DP: Fabric Class
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