1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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)
This commit is contained in:
Santiago Pastorino 2012-04-08 22:30:18 -03:00
parent 2e43159959
commit 6ddbd1844a

View file

@ -1,7 +1,11 @@
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 @@ class Hash
# 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