Class: Container
- Inherits:
-
Object
- Object
- Container
- Defined in:
- lib/container.rb
Defined Under Namespace
Classes: KeyNotFoundError
Instance Method Summary collapse
-
#initialize ⇒ Container
constructor
A new instance of Container.
- #register(key, value) ⇒ Object
- #resolve(key) ⇒ Object
Constructor Details
#initialize ⇒ Container
Returns a new instance of Container.
11 12 13 |
# File 'lib/container.rb', line 11 def initialize @data = {} end |
Instance Method Details
#register(key, value) ⇒ Object
21 22 23 |
# File 'lib/container.rb', line 21 def register(key, value) @data[key] = value end |
#resolve(key) ⇒ Object
15 16 17 18 19 |
# File 'lib/container.rb', line 15 def resolve(key) @data.fetch(key) rescue ::KeyError raise KeyNotFoundError.new(key) end |