From: Robert Dober Date: 2007-01-22T01:01:35+09:00 Subject: Re: Hash pairs at? ------=_Part_179377_24321410.1169395293026 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 1/21/07, dblack@wobblini.net wrote: > > Hi -- > > On Mon, 22 Jan 2007, Phrogz wrote: > > > Phrogz wrote: > >> Trans wrote: > >>> Seems like there should be a mehtod for this: > >> class Hash > >> def entries( *keys ) > >> self.class[ *keys.zip( values_at( *keys ) ).flatten ] > >> end > >> end > > > > Oh, and yes: I'd like a method like this in the core, also. Preferably > > with a more elegant, faster implementation than the above. I find this > > quite useful sometimes. A recent example that comes to mind is taking > > the params hash in Rails and specifying a specific subset of the > > populated values to pass on to another method. > > I'll put in a plug here for flattenx, which lets you flatten by any > number of levels so that you could do the above without the > over-flattening vulnerability. > > http://raa.ruby-lang.org/project/flattenx/ I'd rather see it in the core I have a slight preference for #pairs_at, #entries is not a bad name, but I feel the first is more descriptive. Cheers Robert -- "The best way to predict the future is to invent it." - Alan Kay ------=_Part_179377_24321410.1169395293026--