Use Symbol#name if available in HashWithIndifferentAccess

This is an old feature request that landed on ruby-head
eb67c603ca

This method returns an interned string, so saves an
allocation.
This commit is contained in:
Jean Boussier 2020-09-08 16:39:32 +02:00
parent 7af59e16a2
commit 25b80190f0
1 changed files with 8 additions and 2 deletions

View File

@ -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)