Repository navigation
Make Kernel#silence support :verbose, :warnings and :debug - #330
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Kernel#silence's docs say it accepts:verbose,:debugand:warnings, but passing any of them crashed:Why
silenceonly translated:stderrand:stdoutintoSTDERR/STDOUT. Every other symbol was passed through unchanged and treated as a stream, sosilence(: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:
:verboseand:warningsset$VERBOSE = nil, which silenceswarnand Ruby's own warnings.:debugsets$DEBUG = false.Both are restored afterwards, even if the block raises. Streams work as before, and flags and streams can be mixed:
The docs gain a
silence(:verbose)example.Testing
silencetest 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 sameNoMethodError.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