Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/octopress-deploy/core_ext.rb
Instance Method Summary collapse
-
#deep_merge(hash) ⇒ Object
Merges self with another hash, recursively.
- #to_string_keys ⇒ Object
- #to_symbol_keys ⇒ Object
Instance Method Details
#deep_merge(hash) ⇒ Object
Merges self with another hash, recursively.
This code was lovingly stolen from some random gem: gemjack.com/gems/tartan-0.1.1/classes/Hash.html
Thanks to whoever made it.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/octopress-deploy/core_ext.rb', line 8 def deep_merge(hash) target = dup hash.keys.each do |key| if hash[key].is_a? Hash and self[key].is_a? Hash target[key] = target[key].deep_merge(hash[key]) next end target[key] = hash[key] end target end |
#to_string_keys ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/octopress-deploy/core_ext.rb', line 33 def to_string_keys inject({}) do |memo, (k, v)| if v.is_a? Hash memo[k.to_s] = v.to_string_keys else memo[k.to_s] = v end memo end end |
#to_symbol_keys ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/octopress-deploy/core_ext.rb', line 21 def to_symbol_keys inject({}) do |memo, (k, v)| if v.is_a? Hash memo[k.to_sym] = v.to_symbol_keys else memo[k.to_sym] = v end memo end end |