Class: Hypo::Container
- Inherits:
-
Object
- Object
- Hypo::Container
- Defined in:
- lib/hypo/container.rb
Instance Method Summary collapse
-
#initialize ⇒ Container
constructor
A new instance of Container.
- #register(type, name = nil) ⇒ Object
- #resolve(name) ⇒ Object
Constructor Details
#initialize ⇒ Container
Returns a new instance of Container.
6 7 8 |
# File 'lib/hypo/container.rb', line 6 def initialize @components = {} end |
Instance Method Details
#register(type, name = nil) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/hypo/container.rb', line 10 def register(type, name = nil) component = Component.new(type, self, name) if @components.key?(component.name) raise ContainerError, "Component of type \"#{component.type.to_s}\" has already been registered" end @components[component.name] = component end |
#resolve(name) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/hypo/container.rb', line 19 def resolve(name) unless @components.key?(name) raise ContainerError, "Component with name \"#{name}\" is not registered" end @components[name].instance end |