title: Un-monkey patching a class/method in Ruby
body: <p>I'm trying to unit test a piece of code that I've written in Ruby that calls <code>File.open</code>. To mock it out, I monkeypatched <code>File.open</code> to the following:</p>
  
  <pre><code>class File
    def self.open(name, &amp;block)
      if name.include?("retval")
        return "0\n"
      else
        return "1\n"
      end
    end
  end
  </code></pre>
  
  <p>The problem is that I'm using rcov to run this whole thing since it uses File.open to write code coverage information, it gets the monkeypatched version instead of the real one. <strong>How can I un-monkeypatch this method to revert it to it's original method?</strong> I've tried messing around with <code>alias</code>, but to no avail so far.</p>