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-8.0.0 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-7.2.2 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-7.1.5 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-8.0.0.rc2 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-7.2.1.2 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-7.1.4.2 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-7.0.8.6 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.1.7.10 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-8.0.0.rc1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.1.7.9 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-7.2.1.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-7.1.4.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-7.0.8.5 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-8.0.0.beta1 lib/active_support/core_ext/hash/reverse_merge.rb
omg-activesupport-8.0.0.alpha9 lib/active_support/core_ext/hash/reverse_merge.rb
omg-activesupport-8.0.0.alpha8 lib/active_support/core_ext/hash/reverse_merge.rb
omg-activesupport-8.0.0.alpha7 lib/active_support/core_ext/hash/reverse_merge.rb
omg-activesupport-8.0.0.alpha4 lib/active_support/core_ext/hash/reverse_merge.rb
omg-activesupport-8.0.0.alpha3 lib/active_support/core_ext/hash/reverse_merge.rb
omg-activesupport-8.0.0.alpha2 lib/active_support/core_ext/hash/reverse_merge.rb