A small service collects a daily summary of store events. After a recent PR, the results became unstable: different categories end up with the same values, and data that has already been returned externally can unexpectedly change after subsequent calls.
You need to review the changes and find the causes of the regressions.
add method accepts an event hash with keys :day, :category, and :amount.count;amount_total.snapshot(day) method must return a summary only for the specified day.snapshot result must be safe for external code: reading the result must not affect the service’s internal state, and subsequent add calls must not change an already obtained snapshot.daily_stats.rb.require_relative "./daily_stats"
stats = DailyStats.new
stats.add(day: "2024-05-01", category: "books", amount: 10)
stats.add(day: "2024-05-01", category: "games", amount: 5)
p stats.snapshot("2024-05-01")
first = stats.snapshot("2024-05-01")
stats.add(day: "2024-05-01", category: "books", amount: 2)
p first
p stats.snapshot("2024-05-01")
books and games must accumulate independent values.first variable must remain unchanged after the next add.3.3.0ruby daily_stats.rb or ruby -e '...'DailyStats#add(day:, category:, amount:)day and category are stringsamount is a number supporting +day format is already normalized by the caller; date parsing is not requiredUse line comments to explain the problem, its impact, the fix and how to test it.