Skip to content

Instantly share code, notes, and snippets.

@mizchi
Created October 26, 2009 01:44
Show Gist options
  • Select an option

  • Save mizchi/218368 to your computer and use it in GitHub Desktop.

Select an option

Save mizchi/218368 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
class DataObj
attr_accessor :score
def initialize
@score=0
end
end
class SaveData
attr_accessor :data
def initialize(file_name)
load(file_name)
end
def load(file_name)
if File.exist?(file_name)
@data = File.open(file_name, "rb"){|f| Marshal.load(f) }
else
@data= DataObj.new()
end
end
# 書き込み
def save
File.open("test.dat", "wb"){|f| Marshal.dump(@data, f) }
end
end
save_data = SaveData.new("test.dat") #セーブデータの読み込み
print "#{save_data.data.score}¥n"
save_data.data.score += rand(10)
save_data.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment