Project

General

Profile

Actions

Feature #4184

closed

String that has the same object_id in an each occurrence in a code

Feature #4184: String that has the same object_id in an each occurrence in a code

Added by pavelrosputko (Pavel Rosputko) almost 15 years ago. Updated over 14 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:33802]

Description

=begin
Regexp literals:
5.times { p /abcdasdf/.object_id } -> same!

String literals:
5.times { 'asdasdf'.object_id } -> different

Propose:
5.times { %c(asdasdf).object_id } -> same!

Example of usefullness:

a,b,c,d = data.unpack %c(ccNc) |
e,f,g,h = a.unpack %c(cvaN) | repeated many times

Aspects:

  • String like 'ccNc' are created many times
  • Not modified
  • Used once in code

It is possible to write "class K; Format_ccNc = 'ccNc'; end"
but Format_ccNc will be used only once!

It is logical to make %c() strings frozen.
=end

Actions

Also available in: PDF Atom