Project

General

Profile

Actions

Bug #38329

closed

Avoid string building with << which breaks with frozen strings

Added by Ewoud Kohl van Wijngaarden 30 days ago. Updated 20 days ago.

Status:
Closed
Priority:
Normal
Category:
-
Target version:
-
Difficulty:
Triaged:
No
Fixed in Releases:
Found in Releases:

Description

When dealing with frozen strings, << breaks. Using += unfreezes the string and is thus safer.

[1] pry(main)> msg = 'x'.freeze
=> "x" 
[2] pry(main)> msg.frozen?
=> true
[3] pry(main)> msg << 'y'
FrozenError: can't modify frozen String: "x" (FrozenError)
from (pry):3:in `__pry__'
[4] pry(main)> msg += 'y'
=> "xy" 
[5] pry(main)> msg.frozen?
=> false

Actions

Also available in: Atom PDF