Class: Registry
Class Method Summary collapse
Instance Method Summary collapse
- #get(*keys) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #set(*args) ⇒ Object
Constructor Details
Class Method Details
.clear ⇒ Object
15 16 17 |
# File 'lib/registry.rb', line 15 def clear instance.clear end |
.get(*args) ⇒ Object
7 8 9 |
# File 'lib/registry.rb', line 7 def get(*args) instance.get *args end |
.instance ⇒ Object
3 4 5 |
# File 'lib/registry.rb', line 3 def instance @@instance ||= new end |
.set(*args) ⇒ Object
11 12 13 |
# File 'lib/registry.rb', line 11 def set(*args) instance.set *args end |
Instance Method Details
#get(*keys) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/registry.rb', line 32 def get(*keys) keys.inject self do |result, key| return nil unless result.has_key?(key) result[key] end end |
#set(*args) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/registry.rb', line 25 def set(*args) value, last_key = args.pop, args.pop target = args.inject(self){|result, key| result[key] } value = to_registry(value) if value.is_a?(Hash) target[last_key] = value end |