Skip to content

Instantly share code, notes, and snippets.

@kkchu791
Created November 16, 2015 05:50
Show Gist options
  • Save kkchu791/5cc54e8b6320e9387335 to your computer and use it in GitHub Desktop.
Save kkchu791/5cc54e8b6320e9387335 to your computer and use it in GitHub Desktop.
def save_game(file)
score = 1000
open(file, "w") do |f|
f.puts(score)
f.puts(Time.new.to_i)
end
end
def load_game(file)
open(file, "r") do |f|
raise RuntimeError, "I suspect you of cheating." if f.mtime > f.atime
end
end
save_game("game.sav")
sleep(2)
load_game("game.sav")
open("game.sav", "r+b") { |f| f.write("9") }
load_game("game.sav")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment