module Codebreaker module Entities class Storage FILE_NAME = 'data.yml'.freeze def create File.new(FILE_NAME, 'w') File.write(FILE_NAME, [].to_yaml) end def load YAML.load(File.open(FILE_NAME), [Menu]) if file_exists? end def save(object) File.open(FILE_NAME, 'w') { |file| file.write(YAML.dump(object)) } end def save_game_results(object) create unless file_exists? save(load.push(object)) end private def file_exists? File.exist?(FILE_NAME) end end end end