Created
December 23, 2011 18:32
-
-
Save saturnflyer/1515021 to your computer and use it in GitHub Desktop.
allowing objects to specify exception types
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 Share | |
def call | |
list.each do |address| | |
begin | |
referral = new_referral(address) | |
referral.save | |
rescue referral.invalid_exception_type | |
@unsaved << referral | |
end | |
end | |
end | |
def new_referral(address) | |
Referral.new(address) | |
end | |
end | |
class Referral | |
class Invalid < StandardError; end | |
def invalid_exception_type | |
Referral::Invalid | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My goal with this is to reduce the references to external objects. There is only 1 reference to the Referral class from within Share. If that changes, the replacement merely needs to implement
save
andinvalid_exception_type