Skip to content

Instantly share code, notes, and snippets.

@hugomaiavieira
Created July 24, 2014 19:36
Show Gist options
  • Select an option

  • Save hugomaiavieira/8fb3b5e931591237cd9b to your computer and use it in GitHub Desktop.

Select an option

Save hugomaiavieira/8fb3b5e931591237cd9b to your computer and use it in GitHub Desktop.
Do not use present? on ternary
# 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