From guidoderosa at gmail.com Fri Aug 5 05:59:09 2011 From: guidoderosa at gmail.com (Guido De Rosa) Date: Fri, 5 Aug 2011 02:59:09 -0700 (PDT) Subject: [Facets] deeply "filter" an Hash Message-ID: <11dd7662-a407-40ac-b6d2-4744220fc72e@b19g2000yqj.googlegroups.com> Hi! Given some nested data in form of a Hash: h = { :a => 1, :b => { :x => 10, :y => 20 }, :c=>3 } I would like to "authorize" only certain part of such data to pass in, in a granular way. authorize = { :a => true, :b => { :x => true } } I would like to get this result: filtered = { :a => 1, :b => { :x => 10 } } There's a way to get this in facets? Thanks! Guido From transfire at gmail.com Thu Aug 11 21:37:25 2011 From: transfire at gmail.com (Trans) Date: Thu, 11 Aug 2011 18:37:25 -0700 (PDT) Subject: [Facets] deeply "filter" an Hash In-Reply-To: <11dd7662-a407-40ac-b6d2-4744220fc72e@b19g2000yqj.googlegroups.com> References: <11dd7662-a407-40ac-b6d2-4744220fc72e@b19g2000yqj.googlegroups.com> Message-ID: <04832249-a45d-4c5e-95fb-f269fe5b0928@w24g2000yqw.googlegroups.com> On Aug 5, 5:59?am, Guido De Rosa wrote: > Hi! > > Given some nested data in form of a Hash: > > ? ? h = { > ? ? ? :a => 1, > ? ? ? :b => { > ? ? ? ? :x => 10, > ? ? ? ? :y => 20 > ? ? ? }, > ? ? ? :c=>3 > ? ? } > > I would like to "authorize" only certain part of such data to pass in, > in a granular way. > > ? ? authorize = { > ? ? ? :a => true, > ? ? ? :b => { > ? ? ? ? :x => true > ? ? ? } > ? ? } > > I would like to get this result: > > ? ? filtered = { > ? ? ? :a => 1, > ? ? ? :b => { > ? ? ? ? :x => 10 > ? ? ? } > ? ? } > > There's a way ?to get this in facets? Thanks! The first layer is easy enough: h & [:a, :b] You can do the second with: h[:b] & [:x] But I get the feeling you want something more general. As far as I can recall at the moment, there is no such filtering method. Maybe you would like to create one?