Skip to content

Instantly share code, notes, and snippets.

@mdkent
Created January 11, 2010 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdkent/274741 to your computer and use it in GitHub Desktop.
Save mdkent/274741 to your computer and use it in GitHub Desktop.
--- lib/deep_merge.rb.orig 2010-01-11 10:15:52.000000000 -0800
+++ lib/deep_merge.rb 2010-01-11 15:56:51.000000000 -0800
@@ -51,6 +51,8 @@
# Set to true to sort all arrays that are merged together
# :unpack_arrays DEFAULT: nil
# Set to string value to run "Array::join" then "String::split" against all arrays
+ # :check_for_blanks DEFAULT: false
+ # Use blank? as provided by extlib to help determine if data can be overwritten
# :merge_debug DEFAULT: false
# Set to true to get console output of merge process for debugging
#
@@ -90,10 +92,11 @@
# request that we sort together any arrays when they are merged
sort_merged_arrays = options[:sort_merged_arrays] || false
di = options[:debug_indent] || ''
- # do nothing if source is nil
- if !source || (source.respond_to?(:blank?) && source.blank?) : return dest; end
+ use_blank = options[:check_for_blanks] || false
+ # do nothing if source is nil or alternately blank (as considered by extlib)
+ if source.nil? || use_blank && (source.respond_to?(:blank?) && source.blank?) : return dest; end
# if dest doesn't exist, then simply copy source to it
- if !(dest) && overwrite_unmergeable : dest = source; return dest; end
+ if dest.nil? && overwrite_unmergeable : dest = source; return dest; end
puts "#{di}Source class: #{source.class.inspect} :: Dest class: #{dest.class.inspect}" if merge_debug
if source.kind_of?(Hash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment