ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:110228] [Ruby master Feature#14022] String#surround
       [not found] <redmine.issue-14022.20171018043807.2963@ruby-lang.org>
@ 2022-10-07 12:34 ` schmijos (Josua Schmid)
  2022-10-07 14:04 ` [ruby-core:110230] " austin (Austin Ziegler)
  1 sibling, 0 replies; 2+ messages in thread
From: schmijos (Josua Schmid) @ 2022-10-07 12:34 UTC (permalink / raw
  To: ruby-core

Issue #14022 has been updated by schmijos (Josua Schmid).


I've got another example of how I'd like to use `surround` in Rails string building:

```rb
model_instance.name.presence&.surround('(%s)')
# or
model_instance.name.presence&.surround('(', ')')
```

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

* Author: sawa (Tsuyoshi Sawada)
* Status: Rejected
* Priority: Normal
----------------------------------------
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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:110230] [Ruby master Feature#14022] String#surround
       [not found] <redmine.issue-14022.20171018043807.2963@ruby-lang.org>
  2022-10-07 12:34 ` [ruby-core:110228] [Ruby master Feature#14022] String#surround schmijos (Josua Schmid)
@ 2022-10-07 14:04 ` austin (Austin Ziegler)
  1 sibling, 0 replies; 2+ messages in thread
From: austin (Austin Ziegler) @ 2022-10-07 14:04 UTC (permalink / raw
  To: ruby-core

Issue #14022 has been updated by austin (Austin Ziegler).


schmijos (Josua Schmid) wrote in #note-20:
> I've got another example of how I'd like to use `surround` in Rails string building:
> 
> ```rb
> model_instance.name.presence&.surround('(%s)')
> # or
> model_instance.name.presence&.surround('(', ')')
> ```

```ruby
model_instance.name.presence&.then { "(#{_1})" }
```

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

* Author: sawa (Tsuyoshi Sawada)
* Status: Rejected
* Priority: Normal
----------------------------------------
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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-07 14:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-14022.20171018043807.2963@ruby-lang.org>
2022-10-07 12:34 ` [ruby-core:110228] [Ruby master Feature#14022] String#surround schmijos (Josua Schmid)
2022-10-07 14:04 ` [ruby-core:110230] " austin (Austin Ziegler)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).