Class: Dinjector::Injector
- Inherits:
-
Object
- Object
- Dinjector::Injector
show all
- Defined in:
- lib/dinjector.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
18
19
20
|
# File 'lib/dinjector.rb', line 18
def method_missing(name, *args)
raise NotRegisteredError, "#{name} not registered"
end
|
Instance Method Details
#register(name, singleton = true, &block) ⇒ Object
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/dinjector.rb', line 7
def register(name, singleton = true, &block)
define_singleton_method name do
if singleton
instance_variable_set "@#{name}", (instance_variable_get("@#{name}") || block[self])
instance_variable_get "@#{name}"
else
block[self]
end
end
end
|