class Hash
def slice(*keys)
valid_keys = [:mass, :velocity, :time]
If you have an array of keys you want to limit to, you should splat them:
search(options.slice(:mass, :velocity, :time))
end
criteria.assert_valid_keys(:mass, :velocity, :time)
def search(criteria = {})
limiting an options hash to valid keys before passing to a method:
Slice a hash to include only the given keys. This is useful for
def slice(*keys) keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true) keys.each_with_object(self.class.new) { |k, hash| hash[k] = self[k] if has_key?(k) } end