method
extract!
![Moderate documentation Importance_2](https://d2vfyqvduarcvs.cloudfront.net/images/importance_2.png?1349367920)
v5.1.7 -
Show latest stable
-
2 notes -
Class: Hash
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (0)
- 3.1.0 (38)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (12)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
extract!(*keys)
public
Register or
log in
to add new notes.
freemanoid321 -
September 8, 2013
matthewtuck -
August 13, 2014 - (>= v4.0.2)
![Default_avatar_30](https://www.gravatar.com/avatar/0eb5bf6995005de4e15ed6c0042f7f0b?size=30&default=http://apidock.com/images/default_avatar_30.png)
0 thanks
without a bang
We can use hash#slice if we want an Hash#extract (without bang) like behavior.
![Default_avatar_30](https://www.gravatar.com/avatar/106d7ac8a2e9029d80bdf5a252e792cb?size=30&default=http://apidock.com/images/default_avatar_30.png)
0 thanks
Non-existent key semantics changed.
For Rails 4.0, the behaviour of this has changed when you pass a key that isn’t in the hash.
3.2 (undocumented):
{ a: 1, b: 2 }.extract!(:a, :x) # => {:a=>1, :x => nil}
4.0 (as per docs):
{ a: 1, b: 2 }.extract!(:a, :x) # => {:a=>1}
The 4.0 behaviour is now consistent with the behaviour of slice, the 3.2 behaviour was not.