-1

I read that it was possible to make Ruby exit on warning by redefining Kernel.warn, but I have no idea how. How do I make Ruby exit on warn? Please provide working example.

Michael Lafayette
  • 2,972
  • 3
  • 20
  • 54
  • Note: do not make it check for warnings that may have been generated by/from native code - I just need something that will stop bad Ruby code from running. – Michael Lafayette Jan 02 '16 at 07:57
  • 1
    Of possible interest: @vladr's answer [here](http://stackoverflow.com/questions/660737/can-you-ask-ruby-to-treat-warnings-as-errors/662436#662436). – Cary Swoveland Jan 02 '16 at 08:27
  • Your question is very unclear. What have you tried? What happened? What do you think should have happened instead? Do you know how to define a method in Ruby? Because that's pretty much the answer: define a method named `warn` to do what you want. – Jörg W Mittag Jan 02 '16 at 19:00

1 Answers1

1

Here is one way to override the Kernel#warn

module Kernel
    alias orig_warn warn
    def warn args
        orig_warn args
        exit
    end
end

puts "Foo"
warn "Bar"
puts "Don't want to see this"
Wand Maker
  • 18,476
  • 8
  • 53
  • 87