You don’t have any classes or methods yet for indicating whether recording an expense succeeded or failed. Let’s take a moment to sketch out what that code would look like.
First, you’ll need some kind of storage engine that keeps the expense history; call it a Ledger. The simplest approach would be for the API class to create a Ledger instance directly:
|||class API < Sinatra::Base|
|||@ledger = Ledger.new|
|||super() # rest of initialization from Sinatra|
|||# Later, callers do this:|
|||app = API.new|
But this style limits the code’s flexibility and testability, as it doesn’t allow you to use a substitute ledger for ...