Skip to content

Instantly share code, notes, and snippets.

@dereknguyen269
Created September 5, 2016 13:18
Show Gist options
  • Save dereknguyen269/8f4dbde014ec713bf3ff7f235a946e12 to your computer and use it in GitHub Desktop.
Save dereknguyen269/8f4dbde014ec713bf3ff7f235a946e12 to your computer and use it in GitHub Desktop.
account = Account.find_by_user_id(5)
#account.balance is still 100
#item.price is 80
if account.balance >= item.price
#it's good, allow user to buy this item
account.balance = account.balance - item.price
#account.balance is now 20
account.save
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment