Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to silence Ruby's deprecation warning in 2.4.0?

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?

like image 831
Eli Sadoff Avatar asked Jan 15 '17 02:01

Eli Sadoff


1 Answers

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
like image 132
user2012677 Avatar answered Nov 02 '22 04:11

user2012677