Skip to content

Instantly share code, notes, and snippets.

@methodmissing
Created June 18, 2009 10:56
Show Gist options
  • Select an option

  • Save methodmissing/131847 to your computer and use it in GitHub Desktop.

Select an option

Save methodmissing/131847 to your computer and use it in GitHub Desktop.
module ReverseMerge
# Performs the opposite of <tt>merge</tt>, with the keys and values from the first hash taking precedence over the second.
def reverse_merge(other_hash)
other_hash.merge(self)
end
# Performs the opposite of <tt>merge</tt>, with the keys and values from the first hash taking precedence over the second.
# Modifies the receiver in place.
def reverse_merge!(other_hash)
replace(reverse_merge(other_hash))
end
alias_method :reverse_update, :reverse_merge!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment