Created
October 4, 2012 19:43
-
-
Save tomasv/3835921 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module NotMonkeyPatchable | |
def method_added(name) | |
@methods ||= {} | |
if @methods[name] and not @unpatching | |
@unpatching = true | |
method = @methods[name] | |
define_method(name) { |*args, &block| | |
method.bind(self).call(*args, &block) | |
} | |
@unpatching = false | |
else | |
@methods[name] = instance_method(name) | |
end | |
end | |
end | |
class Monkey | |
extend NotMonkeyPatchable | |
def see | |
'clearly' | |
end | |
def do | |
'do' | |
end | |
end | |
class Monkey | |
def see | |
'patchy' | |
end | |
end | |
class Monkey | |
def see | |
'nothing' | |
end | |
end | |
require 'rspec/autorun' | |
describe Monkey do | |
it 'should see clearly' do | |
subject.see.should == 'clearly' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment