Issue #14022 has been updated by shevegen (Robert A. Heiler).


> After joining the elements of an array into a string using Array#join,
> I frequently need to put substrings before and after the string. 

I do not need to do this often, but I have had a need to do this, largely
due to file names on the *nix commandline that have ' ' characters (space),
so I pad them via '"' like:

    foo bar.mp3

to become:

    "foo bar.mp3"

In particular when I then do system() invocation, e. g. to play via 
mplayer/mpv.


So I can definitely see from which point Tsuyoshi Sawada is coming.

I also think that the name .surround() for String objects is concise
and may make sense, so I am also in +1 support.

So while I am not entirely sure whether this is extremely common, I
think it may be common enough to make this useful. I also agree on
the explanation given by Benoit Daloze, makes a lot of sense what he
wrote to ruby hackers I think. :)

----------------------------------------
Feature #14022: String#surround
https://bugs.ruby-lang.org/issues/14022#change-67328

* 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: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>