Project

General

Profile

Actions

Feature #11346

closed

New #intern_str or similarly-named method of Symbol to return a cached, frozen string (like "string".freeze)

Added by stevej (Steve Jorgensen) over 8 years ago. Updated over 2 years ago.

Status:
Rejected
Target version:
-
[ruby-core:69951]

Description

While I don't think it would be a good idea to change the behavior of the existing Symbol#to_s method as suggested in issue 11066, I think that it would be extremely useful to have some instance method of Symbol to perform that operation.

If such a method is added, it might be nice if String, and maybe even Object offered the same method so the operation could be performed with indifference to the target and so optimizations could be applied to Classes other than just Symbol (e.g. NilClass, TrueClass, FalseClass, and maybe for smallish values of Fixnum).

Perhaps, the new method name would be #intern_str, and if that is added to Object, the default implementation could be something like to_s.intern_str which would abide by the contract of always returning the same frozen string object (assuming #to_s does), even though it builds an ordinary string as an intermediate object, so is not optimized.


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #11066: symbol.to_s performance - caching and returning a frozen stringRejectedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0