Module: TablePrint::HashExtensions::ConstructiveMerge
- Defined in:
- lib/table_print/hash_extensions.rb
Instance Method Summary collapse
Instance Method Details
#constructive_merge(hash) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/table_print/hash_extensions.rb', line 4 def constructive_merge(hash) target = dup hash.keys.each do |key| if hash[key].is_a? Hash and self[key].is_a? Hash target[key].extend ConstructiveMerge target[key] = target[key].constructive_merge(hash[key]) next end target[key] = hash[key] end target end |
#constructive_merge!(hash) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/table_print/hash_extensions.rb', line 20 def constructive_merge!(hash) target = self hash.keys.each do |key| if hash[key].is_a? Hash and self[key].is_a? Hash target[key].extend ConstructiveMerge target[key] = target[key].constructive_merge(hash[key]) next end target[key] = hash[key] end target end |