Each time you call the save method, the available information in the file is overwritten. Whether prompt the method is written correctly? Perhaps that missed something.

 def save(nickname) @code_breakers << Player.new(nickname, @current_try) File.open('result.yaml', 'w') { |file| file.puts(code_breakers.to_yaml) } end 
  • And what do the tests say? :) - D-side
  • it’s still relatively difficult with tests (Rsprec has just started to study. In this connection, I can’t figure out how to write a test to check if a file is overwritten. - Alexandr Dmitrenko
  • Yes, at least write a minitest, it does not matter. How to check? It is very simple, in the test there is an old value and a new one, check if there is something old in it, check if there is a new one. - D-side

1 answer 1

You open the file in the wrong format. We need not "w" (write), but "a" - add.
The answer is https://stackoverflow.com/questions/7085595/file-opening-mode-in-ruby