Slice a nested hash

The attached initializer gives your hashes a #deep_slice method that lets you recursively slice Show archive.org snapshot their contents by a given whitelist of allowed keys and sub-keys:

{ :a => { :b => 'b', :c => 'c' } }.deep_slice(:a => :c) # => { :a => { :c => 'c' } }
Henning Koch Over 11 years ago