No need to build a Set since we're iterating instead of checking for inclusion now

This commit is contained in:
Jeremy Kemper
2008-06-07 18:06:45 -07:00
parent 63679733d8
commit 67e4f16fc5

View File

@@ -1,5 +1,3 @@
require 'set'
module ActiveSupport #:nodoc:
module CoreExtensions #:nodoc:
module Hash #:nodoc:
@@ -14,9 +12,9 @@ module ActiveSupport #:nodoc:
module Slice
# Returns a new hash with only the given keys.
def slice(*keys)
allowed = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys)
keys = keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
hash = {}
allowed.each { |k| hash[k] = self[k] if has_key?(k) }
keys.each { |k| hash[k] = self[k] if has_key?(k) }
hash
end