Issue #9807 has been updated by Matthew Kerwin.


 >
 > That could be a nice solution to avoid all the Array#join and "".tap
 hacks for string creation.
 >
 
 Which hacks are these? Also, I don't see how it's different from
 бн"foo".tap{|s|s<<"bar"}бн
 
 Can you give some examples?

----------------------------------------
Feature #9807: String.new with block
https://bugs.ruby-lang.org/issues/9807#change-46566

* Author: Michael Kohl
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
After a discussion in our team chat today, I wondered if it would be a goodidea to have a version of String.new that accepts a block and works as a string builder. Something like

    string = String.new("foo") do |s|
      s << "bar"
    end
    string #=> "foobar"

If the argument is omitted an empty string would be passed to the block instead.

That could be a nice solution to avoid all the Array#join and "".tap hacks for string creation.



-- 
https://bugs.ruby-lang.org/