class CodebreakerVukolovEdition::Saves
Constants
- FILENAME
Attributes
hint[RW]
secret_code[RW]
state[RW]
time[RW]
turns[RW]
username[RW]
Public Class Methods
new(username, state, game)
click to toggle source
# File lib/saves.rb, line 8 def initialize(username, state, game) @time = Time.now.strftime('%F %T') @username = username @state = state @turns = game.turns @hint = game.hint @secret_code = game.secret_code end
Public Instance Methods
open_database()
click to toggle source
# File lib/saves.rb, line 23 def open_database return File.open(FILENAME, 'a') {|f| f.write Array.new.to_yaml } unless File.exist?(FILENAME) YAML::load_file(FILENAME) end
write_to_file()
click to toggle source
# File lib/saves.rb, line 17 def write_to_file db = open_database new_save = db.push(self) File.open(FILENAME, 'w') {|f| f.write new_save.to_yaml } end