Method: Hash#extract!
- Defined in:
- lib/wedge/utilis/hash.rb
#extract!(*keys) ⇒ Object
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}
{ a: 1, b: 2 }.extract!(:a, :x) # => {:a=>1}
73 74 75 |
# File 'lib/wedge/utilis/hash.rb', line 73 def extract!(*keys) keys.each_with_object(self.class.new) { |key, result| result[key] = delete(key) if has_key?(key) } end |