https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112019-07-13T00:32:36ZRuby Issue Tracking SystemRuby master - Feature #8853: Should String#sub(pattern) returns an Enumerator?https://redmine.ruby-lang.org/issues/8853?journal_id=793702019-07-13T00:32:36Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>File</strong> <a href="/attachments/7900">string-sub-enumerator.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/7900/string-sub-enumerator.patch">string-sub-enumerator.patch</a> added</li><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Feature</i></li><li><strong>ruby -v</strong> deleted (<del><i>ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]</i></del>)</li><li><strong>Backport</strong> deleted (<del><i>1.9.3: UNKNOWN, 2.0.0: UNKNOWN</i></del>)</li></ul><p>If I understand this correctly, this is a feature request to make <code>String#sub</code> and <code>#sub!</code> return an <code>Enumerator</code> if given a single argument and no block. I'm not sure how useful this would be. With <code>#sub!</code>, you can use the enumerator to mutate the string passing the replacement in via <code>Enumerator#feed</code>. However, with <code>#sub</code>, you cannot use the enumerator to modify anything, since the <code>String#sub</code> receiver is not modified, and you can't get access to the resulting string. However, assuming this is desired, the attached patch implements it.</p>