Skip to content

Instantly share code, notes, and snippets.

@tomasv
Created October 4, 2012 19:43
Show Gist options
  • Save tomasv/3835921 to your computer and use it in GitHub Desktop.
Save tomasv/3835921 to your computer and use it in GitHub Desktop.
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