# File lib/automateit/interpreter.rb, line 596
    def add_method_missing_to(object)
      object.instance_variable_set(:@__automateit, self)
      chain = object.respond_to?(:method_missing)

      # XXX The solution below is evil and ugly, but I don't know how else to solve this. The problem is that I want to *only* alter the +object+ instance, and NOT its class. Unfortunately, #alias_method and #alias_method_chain only operate on classes, not instances, which makes them useless for this task.

      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