Created
December 7, 2012 06:34
-
-
Save RyanScottLewis/4231227 to your computer and use it in GitHub Desktop.
Hot Patch a Module
This file contains hidden or 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 HotPatch | |
def hot_patch | |
puts "Sizzlin hot... don't call super here =X" | |
end | |
end | |
class Object | |
def hot_patch | |
meta_class = (class << self; self; end) | |
meta_class.send(:include, HotPatch) unless meta_class.ancestors.include?(HotPatch) | |
send(__method__) | |
end | |
end | |
class Thing | |
end | |
thing = Thing.new | |
thing.hot_patch | |
p Thing.ancestors.include?(HotPatch) | |
p (class << thing; self; end).ancestors.include?(HotPatch) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment