Class: Dee::Container
- Inherits:
-
Object
show all
- Defined in:
- lib/dee/container.rb
Defined Under Namespace
Classes: Factory, SingletonFactory
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Container.
25
26
27
|
# File 'lib/dee/container.rb', line 25
def initialize
@values = Hash.new
end
|
Instance Method Details
#[](key) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/dee/container.rb', line 37
def [](key)
raise "'%s' is not defined in container" % key unless @values.key? key
value = @values[key]
if value.kind_of? Factory
value.create
else
value
end
end
|
#[]=(key, value) ⇒ Object
49
50
51
|
# File 'lib/dee/container.rb', line 49
def []=(key, value)
@values[key] = value
end
|
#factory(key, &block) ⇒ Object
29
30
31
|
# File 'lib/dee/container.rb', line 29
def factory(key, &block)
@values[key] = Factory.new(&block)
end
|
#singleton(key, &block) ⇒ Object
33
34
35
|
# File 'lib/dee/container.rb', line 33
def singleton(key, &block)
@values[key] = SingletonFactory.new(&block)
end
|