Created
September 7, 2014 21:39
-
-
Save davetron5000/c8861340e78a3b10a79f to your computer and use it in GitHub Desktop.
Custom Control Structure
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
# instead of designing a class to return a result object that we | |
# must interrogate, we could design our class to have a custom | |
# control structure to make it easy to see the alternatives | |
# that must be handled | |
PaymentProcessor.new.charge_money(credit_card,amount).on_success do |transaction_id| | |
# happy path | |
end.on_expired_card do | |
# special message to get them to update their card | |
end.on_decline do |decline_message| | |
# general decline | |
end.on_exception do |exception| | |
# something went wrong and we could try again | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment