class RuboCop::Cop::Performance::UnfreezeString
+”
+‘something’
# good
String.new(‘something’)
String.new(”)
String.new
“something”.dup
”.dup
# bad
@example
So, if you expect ‘ASCII-8BIT` encoding, disable this cop.
However, `(+”).encoding` is the same as script encoding(e.g. `UTF-8`).
These differ in encoding. `String.new.encoding` is always `ASCII-8BIT`.
Note: `String.new` (without operator) is not exactly the same as `+”`.
Unary plus operator is faster than `String#dup`.
literal instead of `String#dup` and `String.new`.
In Ruby 2.3 or later, use unary plus operator to unfreeze a string
def on_send(node)
def on_send(node) add_offense(node) if dup_string?(node) || string_new?(node) end