Project

General

Profile

Actions

Feature #14022

closed

String#surround

Added by sawa (Tsuyoshi Sawada) over 6 years ago. Updated over 1 year ago.

Status:
Rejected
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 1 (1 open0 closed)

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0