Eli Sadoff
Eli Sadoff

Reputation: 7308

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?

Upvotes: 6

Views: 1651

Answers (1)

user2012677
user2012677

Reputation: 5745

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

Upvotes: 3

Related Questions