From: dblack@... Date: 2007-01-22T00:31:29+09:00 Subject: Re: Hash pairs at? 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/ David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com)