Skip to content

Commit

Permalink
No need to build a Set since we're iterating instead of checking for …
Browse files Browse the repository at this point in the history
…inclusion now
  • Loading branch information
jeremy committed Jun 8, 2008
1 parent 6367973 commit 67e4f16
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions activesupport/lib/active_support/core_ext/hash/slice.rb
@@ -1,5 +1,3 @@
require 'set'

module ActiveSupport #:nodoc:
module CoreExtensions #:nodoc:
module Hash #:nodoc:
Expand All @@ -14,9 +12,9 @@ module Hash #: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

Expand Down

0 comments on commit 67e4f16

Please sign in to comment.