aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/hash/compact.rb
diff options
context:
space:
mode:
authoryuuji.yaginuma <yuuji.yaginuma@gmail.com>2018-03-03 08:59:38 +0900
committerJeremy Daer <jeremydaer@gmail.com>2018-03-02 16:40:55 -0800
commitacbcec8ea869849f98213fea5e554bb3a82fea61 (patch)
tree4eda1100b0360ba544d9118c6700a1317df283c0 /activesupport/lib/active_support/core_ext/hash/compact.rb
parentb1a9cee83082d6c7a58d87d06055c86fcdbc7644 (diff)
downloadrails-acbcec8ea869849f98213fea5e554bb3a82fea61.tar.gz
rails-acbcec8ea869849f98213fea5e554bb3a82fea61.tar.bz2
rails-acbcec8ea869849f98213fea5e554bb3a82fea61.zip
Deprecate `active_support/core_ext/hash/compact`
Ruby 2.4+ provides `Hash#compact` and `Hash#compact!` natively, so `active_support/core_ext/hash/compact` is no longer necessary.
Diffstat (limited to 'activesupport/lib/active_support/core_ext/hash/compact.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/compact.rb28
1 files changed, 2 insertions, 26 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/compact.rb b/activesupport/lib/active_support/core_ext/hash/compact.rb
index d6364dd9f3..28c8d86b9b 100644
--- a/activesupport/lib/active_support/core_ext/hash/compact.rb
+++ b/activesupport/lib/active_support/core_ext/hash/compact.rb
@@ -1,29 +1,5 @@
# frozen_string_literal: true
-class Hash
- unless Hash.instance_methods(false).include?(:compact)
- # Returns a hash with non +nil+ values.
- #
- # hash = { a: true, b: false, c: nil }
- # hash.compact # => { a: true, b: false }
- # hash # => { a: true, b: false, c: nil }
- # { c: nil }.compact # => {}
- # { c: true }.compact # => { c: true }
- def compact
- select { |_, value| !value.nil? }
- end
- end
+require "active_support/deprecation"
- unless Hash.instance_methods(false).include?(:compact!)
- # Replaces current hash with non +nil+ values.
- # Returns +nil+ if no changes were made, otherwise returns the hash.
- #
- # hash = { a: true, b: false, c: nil }
- # hash.compact! # => { a: true, b: false }
- # hash # => { a: true, b: false }
- # { c: true }.compact! # => nil
- def compact!
- reject! { |_, value| value.nil? }
- end
- end
-end
+ActiveSupport::Deprecation.warn "Ruby 2.4+ (required by Rails 6) provides Hash#compact and Hash#compact! natively, so requiring active_support/core_ext/hash/compact is no longer necessary. Requiring it will raise LoadError in Rails 6.1."