Skip to main content
1 of 2
tokland
  • 11.1k
  • 1
  • 20
  • 25

It's obviously subjective, but IMO inline conditionals make code harder to read, indentation is very important to understand what's going on. So I'd definitely take the second approach, but writing it differently:

existing_transaction = database.find_transaction_by_id(transaction.id)
if !existing_transaction
  database.create_transaction(transaction)
elsif !existing_transaction.processed
  database.update_transaction(transaction)
end
tokland
  • 11.1k
  • 1
  • 20
  • 25