Class: Resque::Kubernetes::DeepHash
- Inherits:
-
Hash
- Object
- Hash
- Resque::Kubernetes::DeepHash
- Defined in:
- lib/resque/kubernetes/deep_hash.rb
Overview
A subclass of Hash that allows nested keys to be added and ensures the interim hashes exist.
Instance Method Summary collapse
-
#deep_add(keys, value) ⇒ Object
Add keys and a value to nested hashes.
Instance Method Details
#deep_add(keys, value) ⇒ Object
Add keys and a value to nested hashes.
keys: An array of keys. value: A value to assign to the key in the ultimate hash.
Example:
h = DeepHash.new
h.deep_add(%w[one two three], "deep")
deep = h["one"]["two"]["three"]
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/resque/kubernetes/deep_hash.rb', line 17 def deep_add(keys, value) last_key = keys.pop m = self keys.each do |key| m[key] ||= {} m = m[key] end m[last_key] = value m end |