From: Trans Date: 2007-01-22T03:12:41+09:00 Subject: Re: Hash pairs at? Robert Dober wrote: > 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. I agree. I think #paris_at is easier to quicky comprehend. Also, I recalled I had added another method to facets that can do this too. I was writing Hash#| and thought I should go ahead and wrote an #& too if reasonable. And lo! There it was: h = {:a=>1,:b=>2,:c=>3} h & [:a,:b] #=> {:a=>1,:b=>2} Code for facets/core/hash/op_and.rb (also op_or.rb): class Hash def &(other) case other when Array k = (keys & other) Hash[*(k.zip(values_at(*k)).flatten)] else Hash.new[*(to_a & other.to_a).flatten] end end def |(other) other.merge self end end Think I still prefer the readability of #pairs_at however. But the above is good to have too. T.