Class: Text2048::HighScore
- Inherits:
-
Object
- Object
- Text2048::HighScore
- Defined in:
- lib/text2048/high_score.rb
Overview
High score manager
Constant Summary collapse
- DB_FILE =
File.('~/.text2048')
Instance Method Summary collapse
-
#initialize ⇒ HighScore
constructor
A new instance of HighScore.
- #load ⇒ Object
- #maybe_update(score) ⇒ Object
- #to_i ⇒ Object
Constructor Details
#initialize ⇒ HighScore
Returns a new instance of HighScore.
9 10 11 12 |
# File 'lib/text2048/high_score.rb', line 9 def initialize @score = 0 load end |
Instance Method Details
#load ⇒ Object
14 15 16 17 |
# File 'lib/text2048/high_score.rb', line 14 def load @score = IO.read(DB_FILE).to_i if FileTest.exists?(DB_FILE) @score end |
#maybe_update(score) ⇒ Object
19 20 21 22 |
# File 'lib/text2048/high_score.rb', line 19 def maybe_update(score) load save(score) if score > @score end |
#to_i ⇒ Object
24 25 26 |
# File 'lib/text2048/high_score.rb', line 24 def to_i @score end |