diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2012-04-08 22:30:18 -0300 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2012-04-08 22:30:20 -0300 |
commit | 6ddbd1844a6fd6aca2992f5f75c9f605cf89808f (patch) | |
tree | eb8f8b2c2512b3dfc83cad5ecfb337d3fe4a3969 | |
parent | 2e431599596913e24d7a5b053b632d0eae83517b (diff) | |
download | rails-6ddbd1844a6fd6aca2992f5f75c9f605cf89808f.tar.gz rails-6ddbd1844a6fd6aca2992f5f75c9f605cf89808f.tar.bz2 rails-6ddbd1844a6fd6aca2992f5f75c9f605cf89808f.zip |
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)
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/keys.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb index da7c3dfbe8..65c3736593 100644 --- a/activesupport/lib/active_support/core_ext/hash/keys.rb +++ b/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 @@ 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 |