Search code examples
rubyactiveresourceactivemodel

A way to silence "warning: Object#type is deprecated; use Object#class"


I have an application that interacts with ActiveResource from a system I have no control of.

It happens that the system sends me a JSON feed and one of the fields is called "type" and, everytime this model is serialized, I get this nasty exception. Since this is a CLI application, it's very annoying.

Is there a way to silence this warning?


Solution

  • Here's one way to silence warnings in certain parts of code:

    def silently(&block)
      warn_level = $VERBOSE
      $VERBOSE = nil
      begin
        result = block.call
      ensure
        $VERBOSE = warn_level
      end
      result
    end
    
    silently do
      #do your thing
    end