Sha256: 9bff399572cbb4dcb405ccd311b4245a1066c41a630af89e80c4cd0465501138

Contents?: true

Size: 666 Bytes

Versions: 232

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

232 entries across 217 versions & 27 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.3.4/lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-8.0.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-8.0.0.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-7.2.2.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-7.1.5.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-7.0.8.7 lib/active_support/core_ext/hash/reverse_merge.rb
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