Class: Tictactoe::Players::Factory
- Inherits:
-
Object
- Object
- Tictactoe::Players::Factory
- Defined in:
- lib/tictactoe/players/factory.rb
Instance Method Summary collapse
- #create(type, mark) ⇒ Object
-
#initialize ⇒ Factory
constructor
A new instance of Factory.
- #register(type, factory) ⇒ Object
Constructor Details
#initialize ⇒ Factory
Returns a new instance of Factory.
4 5 6 |
# File 'lib/tictactoe/players/factory.rb', line 4 def initialize() @factories = {} end |
Instance Method Details
#create(type, mark) ⇒ Object
8 9 10 11 |
# File 'lib/tictactoe/players/factory.rb', line 8 def create(type, mark) raise "No factory has been defined for type: #{type}" unless factories.has_key?(type) factories[type].call(mark) end |
#register(type, factory) ⇒ Object
13 14 15 |
# File 'lib/tictactoe/players/factory.rb', line 13 def register(type, factory) factories[type] = factory end |