提交 6ddbd184 编写于 作者: S Santiago Pastorino

Inline the symbolize_keys/stringify_keys methods

user     system      total        real
symbolize_keys  5.980000   0.070000   6.050000 (  6.048187)
new_symbolize_keys  4.310000   0.050000   4.360000 (  4.364745)
上级 2e431599
class Hash
# Return a new hash with all keys converted to strings.
def stringify_keys
dup.stringify_keys!
result = {}
keys.each do |key|
result[key.to_s] = self[key]
end
result
end
# Destructively convert all keys to strings.
......@@ -15,7 +19,11 @@ def stringify_keys!
# Return a new hash with all keys converted to symbols, as long as
# they respond to +to_sym+.
def symbolize_keys
dup.symbolize_keys!
result = {}
keys.each do |key|
result[(key.to_sym rescue key)] = self[key]
end
result
end
# Destructively convert all keys to symbols, as long as they respond
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册