lib/subhash.rb in subhash-0.1.0 vs lib/subhash.rb in subhash-0.1.1

- old
+ new

@@ -26,25 +26,34 @@ # Rh common module included in Hash and Array class. module Rh public + def merge_cleanup! + _rh_remove_control(self) + end + + def merge_cleanup + _rh_remove_control(rh_clone) + end + + private + # Function which will parse arrays in hierarchie and will remove any control # element (index 0) - def rh_remove_control(result) + def _rh_remove_control(result) return unless [Hash, Array].include?(result.class) if result.is_a?(Hash) - result.each { |elem| rh_remove_control(elem) } + result.each { |elem| _rh_remove_control(elem) } else result.delete_at(0) if result[0].is_a?(Hash) && result[0].key?(:__control) - result.each_index { |index| rh_remove_control(result[index]) } + result.each_index { |index| _rh_remove_control(result[index]) } end + result end - private - # Internal function to determine if result and data key contains both Hash or # Array and if so, do the merge task on those sub Hash/Array # def _rh_merge_recursive(result, key, data) return false unless [Array, Hash].include?(data.class) @@ -563,11 +572,11 @@ # :__unset as a Hash, and :__protected as an Array. _do_rh_merge(result, key, data, true) if data.key?(key) # Remove all control element in arrays - rh_remove_control(result[key]) if result.key?(key) + _rh_remove_control(result[key]) if result.key?(key) end result end @@ -760,10 +769,11 @@ (-(result.length - 1)..-1).each do |index| result.delete_at(index.abs) if result[index.abs] == :unset end _rh_do_array_merge(result, 0, [data_control]) - rh_remove_control(result[0]) # Remove all control elements in tree of arrays + # Remove all control elements in tree of arrays + _rh_remove_control(result[0]) result end def _rh_do_array_merge(result, index, data)