Robert Klemme <shortcutter / googlemail.com> wrote:
> Then people can do this with Strings whose lifetime they know.
> 
> expr_returning_string.auto_clear do |str|
>   puts "We got #{str}."
> end
> 
> In fact, the pattern could be generalized. Not sure though how
> useful this is.

Seems a bit verbose compared to buf.clear...  I'd rather go
farther and reduce object counts, too (not just object sizes);
but that requires API changes.

So I'd like to see stuff like readpartial with the second
(outbuf) arg used more.  Maybe each_line/gets could gain an
`outbuf' arg, too.  But then again, maybe not many people use
readpartial with the `outbuf' arg, either

Anyways, I've been working on a few things the past few days
in stdlib to make things better.  At least #14315 and #14320
won't require end users to call String#clear themselves.

https://bugs.ruby-lang.org/issues/14268
https://bugs.ruby-lang.org/issues/14315
https://bugs.ruby-lang.org/issues/14319
https://bugs.ruby-lang.org/issues/14320

Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>