Skip to content

Instantly share code, notes, and snippets.

@aharpole
Created May 30, 2014 02:24
Show Gist options
  • Save aharpole/736c5dd4a3a62b293a94 to your computer and use it in GitHub Desktop.
Save aharpole/736c5dd4a3a62b293a94 to your computer and use it in GitHub Desktop.
safe use of rescue nil
def chunky_peanut_butter
EndlessChunkyPBSupplier.grab(:chunky_pb)
end
def smooth_peanut_butter
Cabinet.fetch(:smooth_peanut_butter) rescue nil
end
def make_pb_and_j
pb = smooth_peanut_butter || chunky_peanut_butter
...
end
def make_peanut_butter_fudge
pb = smooth_peanut_butter || raise "Only smooth peanut butter will do"
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment