Skip to content

Instantly share code, notes, and snippets.

@kenton
Created November 8, 2012 15:44
Show Gist options
  • Save kenton/4039575 to your computer and use it in GitHub Desktop.
Save kenton/4039575 to your computer and use it in GitHub Desktop.
rp.total_discounts_amt = 0.0
rp.total_discounts_amt?
#=> false
so rp.total_discounts_amt? ? do_this_if_true : do_this_if_false
#=> always evaluates to do_this_if_false
but rp.total_discounts_amt.present? ? do_this_if_true : do_this_if_false
#=> will work as expected based on if value is present or nil
@jayhancock
Copy link

a || 1.0

@jayhancock
Copy link

a = 0.0
b = a || 1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment