views:

36

answers:

1

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?

+2  A: 

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
Skilldrick
This totally rocks! Thank you - http://pastie.org/1218949
kolrie
@kolrie Happy to help :)
Skilldrick
Should returning the $VERBOSE level to before be done in an `ensure` block?
Andrew Grimm
@Andrew - good point, amended.
Skilldrick