    # File lib/plugins/replace.rb, line 4
      def self.delete_and_replace(recent, pattern_reg, replace, global)
        new_text =
          if global
            recent.text.gsub(pattern_reg, replace)
          else
            recent.text.sub(pattern_reg, replace)
          end

        param =
          if recent.in_reply_to_status_id
            {:in_reply_to_status_id => recent.in_reply_to_status_id}
          else
            {}
          end

        if new_text == recent.text
          puts "It was not replaced."
          raise Termtter::CommandCanceled
        end

        if /^y?$/i !~ Readline.readline("\"replace #{new_text}\" [Y/n] ", false)
          puts 'canceled.'
          raise Termtter::CommandCanceled
        else
          result = Termtter::API.twitter.remove_status(recent.id)
          puts "deleted => #{result.text}"
          result = Termtter::API.twitter.update(new_text, param)
          puts "updated => #{result.text}"
        end
      end