Zum Inhalt springen

String Builder Optimization (ARCH6071)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key ruby.performance.string-builder-optimization · Severity info · Category performance

Chaining many + operands in one expression allocates a new string at every intermediate step. Use interpolation, format, or join instead.

def label(user)
"Name: " + user.first + " " + user.last + " (" + user.id.to_s + ")"
end
def label(user)
"Name: #{user.first} #{user.last} (#{user.id})"
end

Replace long + chains with string interpolation or format/join.