Blog

Nov
12
If in doubt, try try again
by Jonathan Siegel | Snippet

If you're new here, you may want to subscribe to our RSS feed. Thanks for visiting!

If in doubt, try try agin

On some recent projects I have seen the following code similar to:


User.find_by_login("noone").id rescue nil

So I just wanted to remind people of the try method.


User.find_by_login("noone").try(:id)

Personally I think try communicates the intent of the code.

No Comments