Skip to content

Instantly share code, notes, and snippets.

Created February 21, 2014 07:45
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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:/
$stderr =$stderr)
Copy link

Thanks for sharing! )

Am I doing something wrong?

$:> irb
=> "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

Copy link

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.

Copy link

rtlong commented Feb 17, 2015


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