module Codebreaker class StatsStorage PATH = './db/data.yml'.freeze def load File.file?(PATH) ? YAML.load_file(PATH) : [] end def add(stat) stats = load stats << stat save(stats) end private def save(stats) Pathname(PATH).dirname.mkpath File.write(PATH, stats.to_yaml) end end end