提交 952ec79b 编写于 作者: C Cheah Chu Yeow 提交者: Jeremy Kemper

Faster Hash#slice that doesn't use Enumerable#include?.

Signed-off-by: NJeremy Kemper <jeremy@bitsweat.net>
上级 714d42d1
......@@ -15,7 +15,9 @@ 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)
reject { |key,| !allowed.include?(key) }
hash = {}
allowed.each { |k| hash[k] = self[k] }
hash
end
# Replaces the hash with only the given keys.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册