Skip to content
Browse files

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)
  • Loading branch information...
1 parent 2e43159 commit 6ddbd1844a6fd6aca2992f5f75c9f605cf89808f @spastorino spastorino committed
Showing with 10 additions and 2 deletions.
  1. +10 −2 activesupport/lib/active_support/core_ext/hash/keys.rb
View
12 activesupport/lib/active_support/core_ext/hash/keys.rb
@@ -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 @@ 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

0 comments on commit 6ddbd18

Please sign in to comment.
Something went wrong with that request. Please try again.