Class: LoyalSpider::HashUtil
- Inherits:
-
Object
- Object
- LoyalSpider::HashUtil
- Defined in:
- lib/loyal_spider/utils/hash_util.rb
Class Method Summary collapse
Class Method Details
.deep_dup(hash) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/loyal_spider/utils/hash_util.rb', line 17 def self.deep_dup hash duplicate = hash.dup duplicate.each_pair do |k,v| tv = duplicate[k] duplicate[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? (self.deep_dup(tv)) : v end duplicate end |
.deep_merge(a_hash, b_hash) ⇒ Object
13 14 15 |
# File 'lib/loyal_spider/utils/hash_util.rb', line 13 def self.deep_merge a_hash, b_hash self.deep_merge! self.deep_dup(a_hash), b_hash end |
.deep_merge!(a_hash, b_hash) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/loyal_spider/utils/hash_util.rb', line 4 def self.deep_merge!(a_hash, b_hash) b_hash.each_pair do |k,v| tv = a_hash[k] a_hash[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? self.deep_merge(a_hash, v) : v end a_hash end |