From: sawadatsuyoshi@... Date: 2017-10-18T06:20:23+00:00 Subject: [ruby-core:83332] [Ruby trunk Feature#14022] String#surround Issue #14022 has been updated by sawa (Tsuyoshi Sawada). @mame In addition to conciseness, I often need to do this kind of string formatting after having done a long method chaining on an array. In that case, having to do string format from the beginning is no convenient. ```ruby "<#{some_array.some_very_long_method_chain.join(", ")}>" ``` It would be easier to read if `surround` were introduced. ```ruby some_array.some_very_long_method_chain.join(", ").surround("<", >") ``` Also, in these use cases, the `join(", ")` operation and surrounding by `"<"` and `">"` are a single logical operation. It makes more sense to to `join(...).surround` than to use a combination of `join` and string interpolation of `"<"` and `">"`. ---------------------------------------- Feature #14022: String#surround https://bugs.ruby-lang.org/issues/14022#change-67289 * Author: sawa (Tsuyoshi Sawada) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- 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: