Skip to content

Instantly share code, notes, and snippets.

@toddsiegel
Last active August 18, 2023 21:59
Show Gist options
  • Save toddsiegel/7474971 to your computer and use it in GitHub Desktop.
Save toddsiegel/7474971 to your computer and use it in GitHub Desktop.
Dependecy Injection
class Payment
def process(gateway)
gateway.verify(self) # duck typed.
end
end
class PaymentTest
def test_process
payment = Payment.new
payment.process(MockGatway.new)
end
end
# in the real code
gateway = AuthNet::Gateway.new # Stripe, Braintree, etc.
payment.process(gateway)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment