Skip to content

CAT 020

unurgunite edited this page Jul 11, 2026 · 3 revisions

CAT-020 — IO::Memory for unread output

Field Value
Severity warning
Confidence high
Auto-fix

IO::Memory for unread output — Creating an IO::Memory just to build a string that's immediately passed to a sink is wasteful. Use String.build instead.

Bad code

io = IO::Memory.new
io << "hello"
io.to_s

Good code

String.build { |io| io << "hello" }

Clone this wiki locally