diff --git a/activesupport/lib/active_support/core_ext/hash/slice.rb b/activesupport/lib/active_support/core_ext/hash/slice.rb index 3f14470f36..88df49a69f 100644 --- a/activesupport/lib/active_support/core_ext/hash/slice.rb +++ b/activesupport/lib/active_support/core_ext/hash/slice.rb @@ -18,7 +18,7 @@ module Slice # Returns a new hash with only the given keys. def slice(*keys) keys = keys.map! { |key| convert_key(key) } if respond_to?(:convert_key) - hash = {} + hash = self.class.new keys.each { |k| hash[k] = self[k] if has_key?(k) } hash end