(This is related to this question).
How can I suppress deprecation warnings in Ruby, until I find time to update the code? Example: The following command will generated a flip-flop is deprecated warning (the command itself is nonsense; I just wanted to provide a minimal, syntactically correct, example):
 ruby -v -e '0 if /a/.../b/'
I already tried
ruby -e '$VERBOSE=nil;0 if /a/.../b/'
and, after installing the warning gem,
 ruby -e 'require "warning";; Warning.ignore(/deprecated/) 0 if /a/.../b/'
but the warning is still printed to stderr. I don't want to redirect the whole stderr to the bit bucket, because I don't want to loose important messages.
The warning is generated by the parser before the code is evaluated. That includes your Warning.ignore code, so the config isn't ready when the warning occurs.
You can move that code into a separate file:
# warn.rb
require 'warning'
Warning.ignore(/deprecated/)
and load it via -r:
$ ruby -r./warn.rb -e '0 if /a/.../b/'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With