Skip to content

Instantly share code, notes, and snippets.

@rkh
Created February 21, 2014 07:45
Show Gist options
  • Save rkh/9130314 to your computer and use it in GitHub Desktop.
Save rkh/9130314 to your computer and use it in GitHub Desktop.
Run Ruby with warnings enabled. Without going crazy.
require 'delegate'
module Support
class WarningFilter < DelegateClass(IO)
def write(line)
super if line !~ /^\S+gems\/ruby\-\S+:\d+: warning:/
end
end
end
$stderr = Support::WarningFilter.new($stderr)
@avakarev
Copy link

Thanks for sharing! )

Am I doing something wrong?

$:> irb
>> RUBY_VERSION
=> "2.1.0"
>> require_relative 'test/warning_filter.rb'
=> true
>> Dir.exists? 'dir'
=> false
$:> irb -w
>> Dir.exists? 'dir'
(irb):1: warning: Dir.exists? is a deprecated name, use Dir.exist? instead
=> false

@rkh
Copy link
Author

rkh commented Feb 21, 2014

Ah, no, it's not supposed to filter out these warnings. It's only supposed to filter out warnings coming from third-party gems. Note that you didn't run with -w in the first example.

@rtlong
Copy link

rtlong commented Feb 17, 2015

THANK YOU!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment