From: Matthias Reitinger Date: 2009-03-09T16:59:29+09:00 Subject: Re: Where's the best version of Hash#pass and Hash#block? Phlip wrote: >> def slice(*keep_keys) > > It's okay, but... > > If I already have an array, I have to splat * it in: > > my_hash.slice(*array) > > Why doesn't slice do the flatten trick here? > > keep_keys = [keep_keys].flatten It would lead to ambiguities if you additionally allowed passing an array of keys. Consider: hsh = { [:one, :two] => [1, 2], :one => 1, :two => 2 } hsh.slice([:one, :two]) Now what should the last line yield? Both { :one => 1, :two => 2 } and { [:one, :two] => [1, 2] } would be valid, depending on how you interpret [:one, :two] (array of keys vs. single key). -Matthias -- Posted via http://www.ruby-forum.com/.