Skip to content

CAT 020

unurgunite edited this page Jul 11, 2026 · 3 revisions

CAT-020 — IO::Memory for unread output

Severity: warning | Confidence: high | Auto-fix:

Tip

This rule supports auto-fix via --fix

Description

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" }

Performance Impact

Tip

This rule can significantly improve performance in hot code paths.

Benchmark

Note

See bench results at bench/cat-020/

Clone this wiki locally