Class: Registry
- Inherits:
-
Hash
show all
- Defined in:
- lib/knightlabs/utils/registry.rb
Instance Method Summary
collapse
Constructor Details
#initialize(registry = {}) ⇒ Registry
Returns a new instance of Registry.
3
4
5
|
# File 'lib/knightlabs/utils/registry.rb', line 3
def initialize(registry={})
self.merge!(registry)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/knightlabs/utils/registry.rb', line 17
def method_missing(method, *args)
if (args.length == 1)
self.put(method.to_s, args[0])
else
self.get(method.to_s)
end
end
|
Instance Method Details
#get(key) ⇒ Object
7
8
9
10
|
# File 'lib/knightlabs/utils/registry.rb', line 7
def get(key)
key = key.is_a?(Symbol) ? (key) : (key.intern)
self[key].is_a?(Proc) ? (self[key].call) : (self[key])
end
|
#put(key, value) ⇒ Object
12
13
14
15
|
# File 'lib/knightlabs/utils/registry.rb', line 12
def put(key, value)
key = key.is_a?(Symbol) ? (key) : (key.intern)
self[key] = value
end
|