From: "Earlopain (Earlopain _) via ruby-core" Date: 2026-07-11T16:32:13+00:00 Subject: [ruby-core:126052] [Ruby Feature#14624] #{nil} allocates a fresh empty string each time Issue #14624 has been updated by Earlopain (Earlopain _). Status changed from Open to Closed `nil.to_s` is frozen and returns the same instance since ruby 2.7 ---------------------------------------- Feature #14624: #{nil} allocates a fresh empty string each time https://bugs.ruby-lang.org/issues/14624#change-118048 * Author: bumblingbear (Dillon Welch) * Status: Closed ---------------------------------------- This causes a bunch of unnecessary string allocations in the following scenario: `"#{'rails' unless boolean_condition} is great"`. Each time this line is called when `boolean_condition` is true, it evaluates to `nil` and when `nil` is interpolated into a string it allocates an empty string. Ideally, the behavior of `nil.to_s` would reference a frozen empty string that wouldn't need to be reallocated each time. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/