Project

General

Profile

Actions

Feature #14022

closed

String#surround

Added by sawa (Tsuyoshi Sawada) almost 4 years ago. Updated over 3 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:83329]

Description

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:

[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:

[1, 2, 3].join(", ").surround("<", ">") # => "<1, 2, 3>"

Related issues

Related to Ruby master - Feature #15024: Support block in Array#joinOpenActions
Actions

Also available in: Atom PDF