def add_method_missing_to(object)
object.instance_variable_set(:@__automateit, self)
chain = object.respond_to?(:method_missing)
template = "def method_missing<%=chain ? '_with_automateit' : ''%>(method, *args, &block)\n### puts \"mm+a(%s, %s)\" % [method, args.inspect]\nif @__automateit.respond_to?(method)\n@__automateit.send(method, *args, &block)\nelse\n<%-if chain-%>\nmethod_missing_without_automateit(method, *args, &block)\n<%-else-%>\nsuper\n<%-end-%>\nend\nend\n<%-if chain-%>\n@__method_missing_without_automateit = self.method(:method_missing)\n\ndef method_missing_without_automateit(*args)\n### puts \"mm-a %s\" % args.inspect\n@__method_missing_without_automateit.call(*args)\nend\n\ndef method_missing(*args)\n### puts \"mm %s\" % args.inspect\nmethod_missing_with_automateit(*args)\nend\n<%-end-%>\n"
text = ::HelpfulERB.new(template).result(binding)
object.instance_eval(text)
end