Skip to content

Make Kernel#silence support :verbose, :warnings and :debug - #330

Merged
trans merged 1 commit into
mainfrom
claude/github-connector-capabilities-4qcre6
Sep 27, 2026
Merged

trans merged 1 commit into
mainfrom
claude/github-connector-capabilities-4qcre6

Conversation

@trans

@trans trans commented Sep 27, 2026

Copy link
Copy Markdown
Member

Kernel#silence's docs say it accepts :verbose, :debug and :warnings, but passing any of them crashed:

undefined method `reopen' for an instance of Symbol (NoMethodError)

Why

silence only translated :stderr and :stdout into STDERR/STDOUT. Every other symbol was passed through unchanged and treated as a stream, so silence(:verbose) ended up calling :verbose.reopen(File::NULL). Nothing in the code ever handled the documented flags.

Fix

The flags now do what the docs describe, for the duration of the block:

  • :verbose and :warnings set $VERBOSE = nil, which silences warn and Ruby's own warnings.
  • :debug sets $DEBUG = false.

Both are restored afterwards, even if the block raises. Streams work as before, and flags and streams can be mixed:

silence(:stdout, :verbose) { noisy_call }

The docs gain a silence(:verbose) example.

Testing

  • The empty silence test placeholder is replaced with 4 tests: :verbose/:warnings, :debug, restoring after a raise, and the return value. Against the old code, they fail with the same NoMethodError.
  • rake test: 1,257 tests pass on CRuby 3.3 and on JRuby 10.1.2 (4 pending).
  • rake qed: 157 demos pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01E2Njj4j1r9twkVcXsMySLW


Generated by Claude Code

The docs listed these, but silence only mapped :stderr and :stdout to
streams and passed every other symbol through as a stream, so
silence(:verbose) raised NoMethodError (undefined method 'reopen' for
Symbol).

:verbose and :warnings now set $VERBOSE to nil, and :debug sets $DEBUG
to false, for the duration of the block. Both are restored afterwards,
even if the block raises. Streams work as before.

Replaces the empty silence test with tests for the flags, restoring
after a raise, and the return value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2Njj4j1r9twkVcXsMySLW
@trans
trans merged commit 1335864 into main Sep 27, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants