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.6 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.0.3.7 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.1.3.2 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-5.2.4.6 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.1.3.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.0.3.6 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-5.2.5 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.1.3 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.1.2.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.0.3.5 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-5.2.4.5 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.1.2 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.1.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.1.0 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.1.0.rc2 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.1.0.rc1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.0.3.4 lib/active_support/core_ext/hash/reverse_merge.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/core_ext/hash/reverse_merge.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-5.2.4.4 lib/active_support/core_ext/hash/reverse_merge.rb