aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorbogdanvlviv <bogdanvlviv@gmail.com>2018-12-20 18:23:15 +0200
committerbogdanvlviv <bogdanvlviv@gmail.com>2018-12-20 18:53:25 +0200
commit25b969a4469d7baefc1b339656008dabd79c975c (patch)
treef662f0ca6ae1952f02b01a2d658881339ea8ccfb /guides
parent3da358ea83b86368021d6f289627d0682d24d30b (diff)
downloadrails-25b969a4469d7baefc1b339656008dabd79c975c.tar.gz
rails-25b969a4469d7baefc1b339656008dabd79c975c.tar.bz2
rails-25b969a4469d7baefc1b339656008dabd79c975c.zip
Follow up #34754
- Fix a few deprecation warnings - Remove testing of `Hash#slice` - Imporve test of `Hash#slice!` - Remove mention about `Hash#slice` from the guide
Diffstat (limited to 'guides')
-rw-r--r--guides/source/active_support_core_extensions.md21
1 files changed, 1 insertions, 20 deletions
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md
index 428271d9b7..3db46bc42e 100644
--- a/guides/source/active_support_core_extensions.md
+++ b/guides/source/active_support_core_extensions.md
@@ -2729,26 +2729,7 @@ NOTE: Defined in `active_support/core_ext/hash/keys.rb`.
### Slicing
-Ruby has built-in support for taking slices out of strings and arrays. Active Support extends slicing to hashes:
-
-```ruby
-{a: 1, b: 2, c: 3}.slice(:a, :c)
-# => {:a=>1, :c=>3}
-
-{a: 1, b: 2, c: 3}.slice(:b, :X)
-# => {:b=>2} # non-existing keys are ignored
-```
-
-If the receiver responds to `convert_key` keys are normalized:
-
-```ruby
-{a: 1, b: 2}.with_indifferent_access.slice("a")
-# => {:a=>1}
-```
-
-NOTE. Slicing may come in handy for sanitizing option hashes with a white list of keys.
-
-There's also `slice!` which in addition to perform a slice in place returns what's removed:
+The method `slice!` replaces the hash with only the given keys and returns a hash containing the removed key/value pairs.
```ruby
hash = {a: 1, b: 2}