X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=vendor%2Frails%2Factivesupport%2Flib%2Factive_support%2Fcore_ext%2Fhash%2Freverse_merge.rb;fp=vendor%2Frails%2Factivesupport%2Flib%2Factive_support%2Fcore_ext%2Fhash%2Freverse_merge.rb;h=546e261cc90e8f59080e1d0b0f9286a15a157847;hb=d115f2e23823271635bad69229a42cd8ac68debe;hp=0000000000000000000000000000000000000000;hpb=37cb670bf3ddde90b214e591f100ed4446469484;p=depot.git
diff --git a/vendor/rails/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb b/vendor/rails/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb
new file mode 100644
index 0000000..546e261
--- /dev/null
+++ b/vendor/rails/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb
@@ -0,0 +1,35 @@
+module ActiveSupport #:nodoc:
+ module CoreExtensions #:nodoc:
+ module Hash #:nodoc:
+ # Allows for reverse merging two hashes where the keys in the calling hash take precedence over those
+ # in the other_hash. This is particularly useful for initializing an option hash with default values:
+ #
+ # def setup(options = {})
+ # options.reverse_merge! :size => 25, :velocity => 10
+ # end
+ #
+ # Using merge, the above example would look as follows:
+ #
+ # def setup(options = {})
+ # { :size => 25, :velocity => 10 }.merge(options)
+ # end
+ #
+ # The default :size and :velocity are only set if the +options+ hash passed in doesn't already
+ # have the respective key.
+ module ReverseMerge
+ # Performs the opposite of merge, 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 merge, 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
+ end
+ end
+end