Skip to content

Instantly share code, notes, and snippets.

@jgaskins
Last active August 31, 2016 17:18
Show Gist options
  • Save jgaskins/ddda6391f2cc8c70abf3c5f2aadf7a25 to your computer and use it in GitHub Desktop.
Save jgaskins/ddda6391f2cc8c70abf3c5f2aadf7a25 to your computer and use it in GitHub Desktop.
Comparing types of dependency injection
class Widget
attr_writer :dependency
def dependency
@dependency ||= Dependency.new
end
end
widget = Widget.new
widget.dependency = StubbedDependency.new
class Widget
def initialize(dependency: Dependency.new)
@dependency = dependency
end
end
widget = Widget.new(dependency: StubbedDependency.new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment