From: William James Date: 2007-01-22T05:45:08+09:00 Subject: Re: Hash pairs at? 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/ class Array def flatten_1 inject([]){|a,x| Array(x).each{|e| a<