Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/fleakr/core_ext/hash.rb
Instance Method Summary collapse
-
#extract!(*keys) ⇒ Object
Extract the matching keys from the source hash and return a new hash with those keys:.
Instance Method Details
#extract!(*keys) ⇒ Object
Extract the matching keys from the source hash and return a new hash with those keys:
>> h = {:a => 'b', :c => 'd'}
=> {:a=>"b", :c=>"d"}
>> h.extract!(:a)
=> {:a=>"b"}
>> h
=> {:c=>"d"}
13 14 15 16 17 18 19 20 |
# File 'lib/fleakr/core_ext/hash.rb', line 13 def extract!(*keys) value = {} keys.each {|k| value.merge!({k => self[k]}) if self.has_key?(k) } keys.each {|k| delete(k) } value end |