timocratic (owner)

Forks

Revisions

gist: 152242 Download_button fork
public
Public Clone URL: git://gist.github.com/152242.git
Embed All Files: show embed
method_visibility.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
module MethodVisibility
  #mocking out super calls is tricky, so here is a hack to get around it.
  def hide_method(method, replacement = Proc.new(){})
    self.send :alias_method, :old_method, method
    self.send :define_method, method, replacement
    begin
      yield
    ensure #otherwise other tests get screwed up if an assertion fails inside block
      self.send :alias_method, method, :old_method
      self.send :remove_method, :old_method
    end
  end
  alias replace_method hide_method
end