Module: CodeBrkrGameTraining::FileOperations
- Included in:
- Game
- Defined in:
- lib/code_brkr_game_training/modules/file_operations.rb
Overview
Module for file operations
Instance Method Summary collapse
Instance Method Details
#load_from_file(path) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/code_brkr_game_training/modules/file_operations.rb', line 12 def load_from_file(path) begin yml_data = File.open(path, &:read) rescue Errno::ENOENT yml_data = '' end YAML.load_stream( yml_data ) end |
#save_to_file(data, path) ⇒ Object
7 8 9 10 |
# File 'lib/code_brkr_game_training/modules/file_operations.rb', line 7 def save_to_file(data, path) yml = YAML.dump(data) File.open(path, 'a') { |yml_file| yml_file.write(yml) } end |