Class: Crazipsum::Registry
- Inherits:
-
Object
- Object
- Crazipsum::Registry
- Includes:
- Singleton
- Defined in:
- lib/crazipsum/registry.rb
Overview
Registry is a singleton class that registers and stores different dictionnary types.
Instance Method Summary collapse
-
#[](type) ⇒ Dictionnary?
Retrieves a dictionnary given its type.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#register(type, words, fillers: []) ⇒ Object
Registers a new type of Dictionnary that can later be retrieved with #[].
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
14 15 16 |
# File 'lib/crazipsum/registry.rb', line 14 def initialize @registry = {} end |
Instance Method Details
#[](type) ⇒ Dictionnary?
Retrieves a dictionnary given its type.
32 33 34 |
# File 'lib/crazipsum/registry.rb', line 32 def [](type) registry[type.to_s] end |
#register(type, words, fillers: []) ⇒ Object
Registers a new type of Dictionnary that can later be retrieved with #[].
24 25 26 |
# File 'lib/crazipsum/registry.rb', line 24 def register(type, words, fillers: []) registry[type.to_s] = Dictionnary.new(words, fillers: fillers) end |