Trans wrote:
> Seesm like there should be a mehtod for this:
> 
>   h = { :a=>1, :b=>2, :c=>3 }
> 
>   h.what_method(:a, :c) #=> { :a=>1, :c=>3 }
>      ^^^^^^^^^^^
> 
> Or is there some other simple way we're supposed to do this?
> 
> T.
> 

h = { :a=>1, :b=>2, :c=>3 }

class Hash
   def restrict(*keys)
     keys.inject({}) {|h,k| h[k] = self[k]; h}
     # alternative:
     #Hash[*keys.zip(values_at(*keys)).flatten]
   end
end

p h.restrict(:a, :c) #=> { :a=>1, :c=>3 }

Maybe there should be something like this in the core?

-- 
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407