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-7.0.4.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.1.7.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.0.6.1 lib/active_support/core_ext/hash/reverse_merge.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-7.0.4 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.1.7 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.0.6 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-7.0.3.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.1.6.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.0.5.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-5.2.8.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-5.2.8 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.0.5 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.1.6 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-7.0.3 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-7.0.2.4 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.1.5.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-6.0.4.8 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-5.2.7.1 lib/active_support/core_ext/hash/reverse_merge.rb
activesupport-5.2.7 lib/active_support/core_ext/hash/reverse_merge.rb