mirror of https://github.com/rails/rails
Document Hash#extract!.
This commit is contained in:
parent
583d7c15c3
commit
308595739c
|
@ -30,6 +30,8 @@ class Hash
|
||||||
omit
|
omit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Removes and returns the key/value pairs matching the given keys.
|
||||||
|
# {:a => 1, :b => 2, :c => 3, :d => 4}.extract!(:a, :b) # => {:a => 1, :b => 2}
|
||||||
def extract!(*keys)
|
def extract!(*keys)
|
||||||
result = {}
|
result = {}
|
||||||
keys.each {|key| result[key] = delete(key) }
|
keys.each {|key| result[key] = delete(key) }
|
||||||
|
|
|
@ -2696,6 +2696,18 @@ hash # => {:a => 1}
|
||||||
|
|
||||||
NOTE: Defined in +active_support/core_ext/hash/slice.rb+.
|
NOTE: Defined in +active_support/core_ext/hash/slice.rb+.
|
||||||
|
|
||||||
|
h4. Extracting
|
||||||
|
|
||||||
|
The method +extract!+ removes and returns the key/value pairs matching the given keys.
|
||||||
|
|
||||||
|
<ruby>
|
||||||
|
hash = {:a => 1, :b => 2}
|
||||||
|
rest = hash.extract!(:a) # => {:a => 1}
|
||||||
|
hash # => {:b => 2}
|
||||||
|
</ruby>
|
||||||
|
|
||||||
|
NOTE: Defined in +active_support/core_ext/hash/slice.rb+.
|
||||||
|
|
||||||
h4. Indifferent Access
|
h4. Indifferent Access
|
||||||
|
|
||||||
The method +with_indifferent_access+ returns an +ActiveSupport::HashWithIndifferentAccess+ out of its receiver:
|
The method +with_indifferent_access+ returns an +ActiveSupport::HashWithIndifferentAccess+ out of its receiver:
|
||||||
|
|
Loading…
Reference in New Issue