From: "austin (Austin Ziegler)" Date: 2022-10-07T14:04:58+00:00 Subject: [ruby-core:110230] [Ruby master Feature#14022] String#surround Issue #14022 has been updated by austin (Austin Ziegler). schmijos (Josua Schmid) wrote in #note-20: > I've got another example of how I'd like to use `surround` in Rails string building: > > ```rb > model_instance.name.presence&.surround('(%s)') > # or > model_instance.name.presence&.surround('(', ')') > ``` ```ruby model_instance.name.presence&.then { "(#{_1})" } ``` ---------------------------------------- Feature #14022: String#surround https://bugs.ruby-lang.org/issues/14022#change-99514 * Author: sawa (Tsuyoshi Sawada) * Status: Rejected * Priority: Normal ---------------------------------------- After joining the elements of an array into a string using `Array#join`, I frequently need to put substrings before and after the string. In such case, I would have to use either of the following: ```ruby [1, 2, 3].join(", ").prepend("<").concat(">") # => "<1, 2, 3>" "<#{[1, 2, 3].join(", ")}>" # => "<1, 2, 3>" "<" + [1, 2, 3].join(", ") + ">" # => "<1, 2, 3>" ``` but none of them is concise enough. I wish there were `String#surround` that works like this: ```ruby [1, 2, 3].join(", ").surround("<", ">") # => "<1, 2, 3>" ``` -- https://bugs.ruby-lang.org/ Unsubscribe: