When a file has the pragma:
# frozen_string_literal: true
all strings written as literals in that file are frozen by default. When I want my strings to be immutable overall, and hence am using the pragma, but want to have a couple of mutable strings, what is the recommended way to write them?
All I can think of is:
String.new("foo")
dup
too. It's just that this is the cool new stuff and the community doesn't have a convention on it yet. – Muskmelon"foo"u
if that is what you are asking. You can't get more concise thanObject#dup
. As for performance, I would be surprised ifString.new
is significantly better. – Muskmelon