Module: Codebreaker::Loader
- Defined in:
- lib/codebreaker/loader.rb
Constant Summary collapse
- EXTENCTION =
'.yml'
Class Method Summary collapse
Class Method Details
.load(file_name) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/codebreaker/loader.rb', line 6 def self.load(file_name) file_name = File.(file_name) + EXTENCTION.to_s if File.exist?(file_name) YAML.load_file(file_name) else File.new(file_name, 'w') [] end end |
.save(obj, file_name) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/codebreaker/loader.rb', line 16 def self.save(obj, file_name) file_name = File.(file_name) + EXTENCTION.to_s stats = File.file?(file_name) && !File.zero?(file_name) ? YAML.load_file(file_name) : [] stats << obj file = File.open(file_name, 'w') file.write(stats.to_yaml) file.close end |