Last active
August 18, 2023 21:59
-
-
Save toddsiegel/7474971 to your computer and use it in GitHub Desktop.
Dependecy Injection
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 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