Module: Codebreaker::Data

Included in:
Game
Defined in:
lib/codebreaker/data.rb

Instance Method Summary collapse

Instance Method Details

#loadObject



11
12
13
14
15
16
# File 'lib/codebreaker/data.rb', line 11

def load
  file = File.open('/app/lib/data.yaml')
  games = []
  file.nil? ? "No #{file} file found." : YAML.load_stream(file) { |doc| games << doc }
  games
end

#saveObject



4
5
6
7
8
9
# File 'lib/codebreaker/data.rb', line 4

def save
  File.open('/app/lib/data.yaml', 'a') do |file|
    YAML.dump({ player: @player, hints_left: @hints_left, \
                attempts: @attempts, score: score }, file)
  end
end