Sha256: 9bff399572cbb4dcb405ccd311b4245a1066c41a630af89e80c4cd0465501138

Contents?: true

Size: 666 Bytes

Versions: 226

Compression:

Stored size: 666 Bytes

Contents

# frozen_string_literal: true

class Hash
  # Merges the caller into +other_hash+. For example,
  #
  #   options = options.reverse_merge(size: 25, velocity: 10)
  #
  # is equivalent to
  #
  #   options = { size: 25, velocity: 10 }.merge(options)
  #
  # This is particularly useful for initializing an options hash
  # with default values.
  def reverse_merge(other_hash)
    other_hash.merge(self)
  end
  alias_method :with_defaults, :reverse_merge

  # Destructive +reverse_merge+.
  def reverse_merge!(other_hash)
    replace(reverse_merge(other_hash))
  end
  alias_method :reverse_update, :reverse_merge!
  alias_method :with_defaults!, :reverse_merge!
end

Version data entries

226 entries across 211 versions & 26 rubygems

Version Path
activesupport-5.2.0 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-5.2.0.rc2 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-5.2.0.rc1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-5.2.0.beta2 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-5.2.0.beta1 lib/active_support/core_ext/hash/reverse_merge.rb
ruby-on-quails-0.1.0 activesupport/lib/active_support/core_ext/hash/reverse_merge.rb