Skip to content

Commit

Permalink
Merge pull request #390 from amatsuda/ruby25_hash_slice
Browse files Browse the repository at this point in the history
Fix Hash#slice behavior not to return a subclass instance
  • Loading branch information
radar committed Nov 1, 2017
2 parents 0a0fa8e + a3257e4 commit 329ba05
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
4 changes: 2 additions & 2 deletions 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)
Expand All @@ -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!)
Expand Down
6 changes: 0 additions & 6 deletions test/core_ext/hash_test.rb
Expand Up @@ -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' }
Expand Down

0 comments on commit 329ba05

Please sign in to comment.