Permalink
Browse files

Document Hash#extract!.

  • Loading branch information...
1 parent 927d3c2 commit ebf0cc4ceada4d945fc15c56a02ea97bf4e5fc57 @smartinez87 smartinez87 committed with fxn Aug 15, 2011
@@ -30,6 +30,8 @@ def slice!(*keys)
omit
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)
result = {}
keys.each {|key| result[key] = delete(key) }
@@ -2694,6 +2694,18 @@ hash # => {:a => 1}
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
The method +with_indifferent_access+ returns an +ActiveSupport::HashWithIndifferentAccess+ out of its receiver:

0 comments on commit ebf0cc4

Please sign in to comment.