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

Updated by stevej (Steve Jorgensen) over 8 years ago

In the description, "(assuming #to_s does)" should read "(assuming #to_s returns equivalent strings)".

Actions #2

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Related to Feature #11066: symbol.to_s performance - caching and returning a frozen string added
Actions #3

Updated by ko1 (Koichi Sasada) over 8 years ago

  • Assignee set to matz (Yukihiro Matsumoto)

Any opinion?

Updated by jeremyevans0 (Jeremy Evans) over 2 years ago

  • Status changed from Open to Closed

Symbol#name was added in Ruby 3.0 for this.

Actions #5

Updated by ko1 (Koichi Sasada) over 2 years ago

  • Status changed from Closed to Rejected
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0