Slice a nested hash

The attached initializer gives your hashes a #deep_slice method that lets you recursively slice 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 almost 9 years ago
This website uses short-lived cookies to improve usability.
Accept or learn more