Class: Game
- Inherits:
-
Object
- Object
- Game
- Defined in:
- lib/models/game.rb
Instance Attribute Summary collapse
-
#draws ⇒ Object
Returns the value of attribute draws.
-
#id ⇒ Object
Returns the value of attribute id.
-
#player_name ⇒ Object
Returns the value of attribute player_name.
-
#score ⇒ Object
Returns the value of attribute score.
-
#wins ⇒ Object
Returns the value of attribute wins.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Game
constructor
A new instance of Game.
- #save! ⇒ Object
Constructor Details
#initialize ⇒ Game
Returns a new instance of Game.
24 25 26 27 28 29 30 |
# File 'lib/models/game.rb', line 24 def initialize @id = nil @player_name = nil @wins = 0 @draws = 0 @score = 0 end |
Instance Attribute Details
#draws ⇒ Object
Returns the value of attribute draws.
22 23 24 |
# File 'lib/models/game.rb', line 22 def draws @draws end |
#id ⇒ Object
Returns the value of attribute id.
22 23 24 |
# File 'lib/models/game.rb', line 22 def id @id end |
#player_name ⇒ Object
Returns the value of attribute player_name.
22 23 24 |
# File 'lib/models/game.rb', line 22 def player_name @player_name end |
#score ⇒ Object
Returns the value of attribute score.
22 23 24 |
# File 'lib/models/game.rb', line 22 def score @score end |
#wins ⇒ Object
Returns the value of attribute wins.
22 23 24 |
# File 'lib/models/game.rb', line 22 def wins @wins end |
Class Method Details
.map ⇒ Object
7 8 9 |
# File 'lib/models/game.rb', line 7 def map @games.map { |game_ary| yield game_ary } end |
.next_id ⇒ Object
11 12 13 |
# File 'lib/models/game.rb', line 11 def next_id @games.length + 1 end |
.save(game) ⇒ Object
15 16 17 18 19 |
# File 'lib/models/game.rb', line 15 def save(game) game.id = next_id @games << game File.open("lib/games.yml", "w") { |file| file.write(@games.to_yaml) } end |
Instance Method Details
#save! ⇒ Object
32 33 34 |
# File 'lib/models/game.rb', line 32 def save! self.class.save(self) end |