From a3257e4c55999ba0a5bf012992a9db327247fb73 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 27 Oct 2017 11:12:57 +0900 Subject: [PATCH] Revert "Maintain subclasses of Hash when calling Hash#slice." This reverts commit 6f291c427bd2df08037fbc500c529fa71b167f97. This I18n original Hash#slice implementation behaves differently from that of Ruby 2.5+ --- lib/i18n/core_ext/hash.rb | 4 ++-- test/core_ext/hash_test.rb | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/i18n/core_ext/hash.rb b/lib/i18n/core_ext/hash.rb index 0c254ecc..895f41a4 100644 --- a/lib/i18n/core_ext/hash.rb +++ b/lib/i18n/core_ext/hash.rb @@ -1,6 +1,6 @@ class Hash def slice(*keep_keys) - h = self.class.new + h = {} keep_keys.each { |key| h[key] = fetch(key) if has_key?(key) } h end unless Hash.method_defined?(:slice) @@ -21,7 +21,7 @@ def deep_symbolize_keys MERGER = proc do |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &MERGER) : v2 end - + def deep_merge!(data) merge!(data, &MERGER) end unless Hash.method_defined?(:deep_merge!) diff --git a/test/core_ext/hash_test.rb b/test/core_ext/hash_test.rb index 7325c50a..f7ebd6fe 100644 --- a/test/core_ext/hash_test.rb +++ b/test/core_ext/hash_test.rb @@ -20,12 +20,6 @@ class I18nCoreExtHashInterpolationTest < I18n::TestCase assert_equal expected, hash.slice(:foo, :not_here) end - test "#slice maintains subclasses of Hash" do - klass = Class.new(Hash) - hash = klass[:foo, 'bar', :baz, 'bar'] - assert_instance_of klass, hash.slice(:foo) - end - test "#except" do hash = { :foo => 'bar', :baz => 'bar' } expected = { :foo => 'bar' }