Skip to content

Instantly share code, notes, and snippets.

@rubysolo
Created July 24, 2012 19:30
Show Gist options
  • Save rubysolo/3172105 to your computer and use it in GitHub Desktop.
Save rubysolo/3172105 to your computer and use it in GitHub Desktop.
require 'debugger'
class Node
def to_s
"new hotness"
end
end
class Module
def method_added(method_id)
puts "added method #{ method_id } to #{ self } (which is a #{ self.class })."
if self.ancestors.include?(Node) && method_id == :to_s && ! self.respond_to?(:hooked?)
puts " ==> redefining..."
self.class_eval do
alias_method :original_to_s, :to_s
def self.hooked?
true
end
def to_s(*args)
super(*args) + ' ' + original_to_s
end
end
end
end
end
class SubNode < Node
def to_s
"old & busted"
end
end
puts Node.new
puts SubNode.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment