Skip to content

Instantly share code, notes, and snippets.

@RyanScottLewis
Created December 7, 2012 06:34
Show Gist options
  • Save RyanScottLewis/4231227 to your computer and use it in GitHub Desktop.
Save RyanScottLewis/4231227 to your computer and use it in GitHub Desktop.
Hot Patch a Module
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