Skip to content

Instantly share code, notes, and snippets.

@gotjosh
Last active April 22, 2016 14:45
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 gotjosh/7282a7fc65c32e0c4c476cb1f5656be9 to your computer and use it in GitHub Desktop.
Save gotjosh/7282a7fc65c32e0c4c476cb1f5656be9 to your computer and use it in GitHub Desktop.
# Current
def initialize(resource = nil)
@resource = resource
end
private
def resource
@resource ||= ProductResource.new(connection: ExternalAdapter.instance.connection)
end
# Scenario 1
def initialize(resource = ProductResource.new(connection: ExternalAdapter.instance.connection))
@resource = resource
end
# Scenario 2
def initialize(resource = ProductResource.build)
@resource = resource
end
class ProductResource
def self.build(adapter = ExternalAdapter.instance.connection)
new(connection: adapter)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment