6

Since Ruby 2.4.0, there has been a deprecation warning for using certain features that have been deprecated. For example, Bignum, Fixnum, TRUE, and FALSE will all trigger deprecation warnings. While I'm fixing my code, there is a fair amount of code that I would like it silenced for, especially in Rails. How can I do this?

Eli Sadoff
  • 7,173
  • 6
  • 33
  • 61

1 Answers1

3
module Kernel
  def suppress_warnings
    original_verbosity = $VERBOSE
    $VERBOSE = nil
    result = yield
    $VERBOSE = original_verbosity
    return result
  end
end


>> X = :foo
=> :foo
>> X = :bar
(irb):11: warning: already initialized constant X
=> :bar
>> suppress_warnings { X = :baz }
=> :baz
user2012677
  • 5,465
  • 6
  • 51
  • 113
  • 2
    This is good for code that I've written, but is there a way to get Ruby to run all code like this on the whole? – Eli Sadoff Jan 15 '17 at 16:24