Ruby

Ruby

Made by DeepSource

Use unary plus to get an unfrozen string literal RB-PR1024

Performance
Major

Unary plus operator is faster than String#dup.

Note: String.new (without operator) is not exactly the same as +''. These differ in encoding. String.new.encoding is always ASCII-8BIT. However, (+'').encoding is the same as script encoding(e.g. UTF-8). So, if you expect ASCII-8BIT encoding, disable this issue, either in .rubocop.yml, or in the occurrence it was raised, using skipcq.

Bad practice

''.dup
"something".dup
String.new
String.new('')
String.new('something')

Recommended

+'something'
+''