diff options
author | Mikhail Dieterle <MikDiet@gmail.com> | 2012-09-21 11:43:59 +0300 |
---|---|---|
committer | Mikhail Dieterle <MikDiet@gmail.com> | 2012-10-08 01:20:37 +0300 |
commit | a4b11961630febd556c962b788b11c0ed5bedb45 (patch) | |
tree | 4e0e8fd0575e898d6ce54fcd77284030220086d4 /guides | |
parent | 5d27338ab08496b41ef71c789e5ae4de0b3b8df7 (diff) | |
download | rails-a4b11961630febd556c962b788b11c0ed5bedb45.tar.gz rails-a4b11961630febd556c962b788b11c0ed5bedb45.tar.bz2 rails-a4b11961630febd556c962b788b11c0ed5bedb45.zip |
add more testcases and doc about Hash#extract!
Diffstat (limited to 'guides')
-rw-r--r-- | guides/source/active_support_core_extensions.md | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index 2a84242b9c..53f0579b0f 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -2867,8 +2867,16 @@ The method `extract!` removes and returns the key/value pairs matching the given ```ruby hash = {:a => 1, :b => 2} -rest = hash.extract!(:a) # => {:a => 1} -hash # => {:b => 2} +rest = hash.extract!(:a, :x) # => {:a => 1} # non-existing keys are ignored +hash # => {:b => 2} +``` + +The method `extract!` returns the same subclass of Hash, that the receiver is. + +```ruby +hash = {:a => 1, :b => 2}.with_indifferent_access +rest = hash.extract!(:a).class +# => ActiveSupport::HashWithIndifferentAccess ``` NOTE: Defined in `active_support/core_ext/hash/slice.rb`. |