From 25b80190f06e90967bc167ec8e1a7d52c358bdae Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Tue, 8 Sep 2020 16:39:32 +0200 Subject: [PATCH] Use Symbol#name if available in HashWithIndifferentAccess This is an old feature request that landed on ruby-head https://github.com/ruby/ruby/commit/eb67c603ca7e435181684857e650b4633fda5bb6 This method returns an interned string, so saves an allocation. --- .../lib/active_support/hash_with_indifferent_access.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 6bca9d86ff..26a9db0654 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -363,8 +363,14 @@ module ActiveSupport end private - def convert_key(key) - key.kind_of?(Symbol) ? key.to_s : key + if Symbol.method_defined?(:name) + def convert_key(key) + key.kind_of?(Symbol) ? key.name : key + end + else + def convert_key(key) + key.kind_of?(Symbol) ? key.to_s : key + end end def convert_value(value, conversion: nil)