Created
July 24, 2014 19:36
-
-
Save hugomaiavieira/8fb3b5e931591237cd9b to your computer and use it in GitHub Desktop.
Do not use present? on ternary
This file contains hidden or 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
| # you may think to do this: | |
| bar = foo || {} | |
| # but foo can and empty string that is not falsy, so you do this: | |
| bar = foo.present? ? foo : {} | |
| # a better way to do it is this one: | |
| bar = foo.presence || {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment