From 9f36900d5c94563510cbcca5bcf0d751d595347f Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Mon, 2 Jun 2008 01:42:38 -0700 Subject: [PATCH] Faster Hash#slice that doesn't use Enumerable#include?. --- .../lib/active_support/core_ext/hash/slice.rb | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/hash/slice.rb b/activesupport/lib/active_support/core_ext/hash/slice.rb index 6fe5e05..44b6964 100644 --- a/activesupport/lib/active_support/core_ext/hash/slice.rb +++ b/activesupport/lib/active_support/core_ext/hash/slice.rb @@ -15,7 +15,9 @@ module ActiveSupport #:nodoc: # 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) - reject { |key,| !allowed.include?(key) } + hash = {} + allowed.each { |k| hash[k] = self[k] } + hash end # Replaces the hash with only the given keys. -- 1.5.5.1