diff options
author | Akira Matsuda <ronnie@dio.jp> | 2017-10-21 17:22:45 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2017-10-21 17:44:18 +0900 |
commit | d6f3b91aaa4af88eda2344629afed64640d51e0f (patch) | |
tree | f809f7fa98cf2b137886136e4bd82aaf7b8cd496 /activesupport/lib/active_support | |
parent | a524c955bfcce118da0ecb21affe28e2a102a54b (diff) | |
download | rails-d6f3b91aaa4af88eda2344629afed64640d51e0f.tar.gz rails-d6f3b91aaa4af88eda2344629afed64640d51e0f.tar.bz2 rails-d6f3b91aaa4af88eda2344629afed64640d51e0f.zip |
Move HWIA specific logic for slice and slice! to HWIA class
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/slice.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/hash_with_indifferent_access.rb | 10 |
2 files changed, 10 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/slice.rb b/activesupport/lib/active_support/core_ext/hash/slice.rb index 6a25e779e9..ed6cd9609a 100644 --- a/activesupport/lib/active_support/core_ext/hash/slice.rb +++ b/activesupport/lib/active_support/core_ext/hash/slice.rb @@ -21,7 +21,6 @@ class Hash # valid_keys = [:mass, :velocity, :time] # search(options.slice(*valid_keys)) def slice(*keys) - keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true) keys.each_with_object(self.class.new) { |k, hash| hash[k] = self[k] if has_key?(k) } end unless method_defined?(:slice) @@ -31,7 +30,6 @@ class Hash # { a: 1, b: 2, c: 3, d: 4 }.slice!(:a, :b) # # => {:c=>3, :d=>4} def slice!(*keys) - keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true) omit = slice(*self.keys - keys) hash = slice(*keys) hash.default = default diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index fcc13feb8c..f8bff4fe3e 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -311,6 +311,16 @@ module ActiveSupport dup.tap { |hash| hash.transform_keys!(*args, &block) } end + def slice(*keys) + keys.map! { |key| convert_key(key) } + self.class.new(super) + end + + def slice!(*keys) + keys.map! { |key| convert_key(key) } + super + end + def compact dup.tap(&:compact!) end |