Project

General

Profile

Feature #17104

Updated by sawa (Tsuyoshi Sawada) over 4 years ago

I think the point of frozen string literals is to avoid needless allocations. Interpolated strings are allocated each time, so freezing them appears pointless.  

 ```rb 
 #frozen_string_literal: true 

 def foo(str) 
   "#{str}" 
 end 

 fr1 = 'a' 
 fr2 = 'a' 
 fr1_1 = foo(fr1) 
 fr2_1 = foo(fr2) 

 puts fr1.__id__, fr2.__id__, fr1_1.__id__, fr2_1.__id__ 

 puts fr1_1 << 'b' 
 ``` 
 

 Isn't the point of frozen literals to avoid needless allocations? But interpolated strings are allocated each time, so freezing appears pointless.  

Back