-
-
Save avdi/1516514 to your computer and use it in GitHub Desktop.
allowing objects to specify exception types
This file contains hidden or 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 Share | |
| def call | |
| list.each do |address| | |
| referral = new_referral(address) | |
| # All else being equal, I'd probably prefer a caller-specified | |
| # fallback strategy | |
| referral.save do | |
| @unsaved << referral | |
| end | |
| end | |
| end | |
| def new_referral(address) | |
| Referral.new(address) | |
| end | |
| end | |
| class Referral | |
| class Invalid < StandardError; end | |
| def save | |
| # ... | |
| # if invalid: | |
| if block_given? then yield else raise Invalid end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your thoughts on this!