Class: Gameworks::GameRegistry
- Inherits:
-
Object
- Object
- Gameworks::GameRegistry
- Defined in:
- lib/gameworks/game_registry.rb
Instance Method Summary collapse
- #add(game) ⇒ Object
- #as_json ⇒ Object
-
#initialize ⇒ GameRegistry
constructor
A new instance of GameRegistry.
- #instance(id) ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize ⇒ GameRegistry
Returns a new instance of GameRegistry.
3 4 5 |
# File 'lib/gameworks/game_registry.rb', line 3 def initialize @instances = {} end |
Instance Method Details
#add(game) ⇒ Object
7 8 9 |
# File 'lib/gameworks/game_registry.rb', line 7 def add(game) @instances[game.id] = game end |
#as_json ⇒ Object
15 16 17 18 19 |
# File 'lib/gameworks/game_registry.rb', line 15 def as_json @instances.map do |id, game| { 'id' => game.id, 'state' => game.state } end end |
#instance(id) ⇒ Object
11 12 13 |
# File 'lib/gameworks/game_registry.rb', line 11 def instance(id) @instances[id] end |
#to_json ⇒ Object
21 22 23 |
# File 'lib/gameworks/game_registry.rb', line 21 def to_json as_json.to_json end |