Skip to content

Instantly share code, notes, and snippets.

@vitaly-pushkar
Created January 23, 2020 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitaly-pushkar/20f08cbdf3361afdb348c7a5c13e6726 to your computer and use it in GitHub Desktop.
Save vitaly-pushkar/20f08cbdf3361afdb348c7a5c13e6726 to your computer and use it in GitHub Desktop.
From the blog post "Error Handling with Either Monads in Ruby"
def find_user(id)
Try { user_model.find_by(id: id) }
end
def update_user(user, data)
Try do
user.update(data)
user.reload
end
end
def send_email(email, reason)
Try { mailer.deliver!(email, template: reason) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment