From: duerst@... Date: 2017-10-23T08:52:13+00:00 Subject: [ruby-core:83520] [Ruby trunk Feature#14022] String#surround Issue #14022 has been updated by duerst (Martin D��rst). Two comments/ideas: 1. If the starting string and the ending string in `surround` are the same, it should be enough to give them only once: ````Ruby "Hello World!".surround("'") #=> "'Hello World!'" ```` 2. As the examples above mention `join` a lot, it may also be possible to add two additional arguments to join: ``` [1, 2, 3, 4].join(", ", "<", ">") #=> "<1, 2, 3, 4>" ``` I would definitely use something like this, e.g. in ``` array_of_lines.join("\n", "", "\n") #=> lines concatenated with newlines, ending with newline ``` ---------------------------------------- Feature #14022: String#surround https://bugs.ruby-lang.org/issues/14022#change-67545 * 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: