Skip to content

Instantly share code, notes, and snippets.

@avdi
Forked from saturnflyer/gist:1515021
Created December 24, 2011 06:10
Show Gist options
  • Select an option

  • Save avdi/1516514 to your computer and use it in GitHub Desktop.

Select an option

Save avdi/1516514 to your computer and use it in GitHub Desktop.
allowing objects to specify exception types
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
@saturnflyer
Copy link

Thanks for your thoughts on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment